[{"server":null,"owner":null,"id":"77bb1bed-e2c1-4bad-9f50-d7ae59dee096","params":{"result":{"value":null,"datetime":1555659041,"status":null,"version":0},"hash":{"value":"CH9iTjX9gaGmyfgmikXgMg==","datetime":1555660301,"status":null,"version":0},"enabled":{"value":true,"datetime":1555659309,"status":null,"version":0},"error_text":{"value":null,"datetime":1555659832,"status":null,"version":0},"type":{"value":"EgsObjectUpdated","datetime":1555659043,"status":null,"version":0},"settings":{"value":"{\"item_type\":\"Sensor\",\"item_pin\":\"zoneInputPin\",\"proxy_type\":\"Zone\",\"proxy_pin\":\"zoneOutputPin\",\"table\":\"{}\"}","datetime":1555660579,"status":null,"version":0},"state":{"value":"ok.normal","datetime":1555659832,"status":null,"version":0},"script":{"value":"# имя: 'Proxy item 3'\r\n# описание: прокси - заместитель связанного устройства\r\n# тип триггера: 'EgsObjectUpdated'\r\n# создан: 2018.02.28 17.37.48, Сельченков Н.Ю.\r\n# изменен: '2019.04.19 11.51.39', Сельченков Н.Ю.\r\n# подробности: https://redmine.integra-s.com:11000/projects/eilyacuario/wiki/Proxy_item_3\r\n\r\nuse Newtonsoft.Json.Linq.JObject as JObject\r\nuse Newtonsoft.Json.JsonConvert as JsonConvert from Newtonsoft.Json\r\n\r\nuse typedef\r\n`\r\n    <root>\r\n        <param name=\"item_type\" />\r\n        <param name=\"item_pin\" />\r\n        <param name=\"proxy_type\" />\r\n        <param name=\"proxy_pin\" />\r\n        <param name=\"table\" />\r\n    </root>\r\n` as Settings\r\n\r\nconst settings = Settings(trigger.settings)\r\nconst table    = JsonConvert.DeserializeObject(settings.table, JObject) as JObject\r\n\r\nuse (\"acuario2.types.\" + settings.item_type) as ItemType from acuario2.types\r\nuse (\"acuario2.types.\" + settings.proxy_type) as ProxyType from acuario2.types\r\n\r\nif @object is Item then\r\n    let item = @object as ItemType \r\n    if (item isnt nil) and (\"state\" in changes) then\r\n        let source = item[\"state\"]\r\n        from item.(settings.item_pin).GetOppositeItems() where it is ProxyType do \r\n            let target = it[\"state\"]\r\n            let value  = from table.Properties() where source.Text like Name select Value try first\r\n            if value isnt null then target.Set(value, source.Status, source.DateTime)\r\n            else if source.Text in target.EnumNames then target.Set(source.Text, source.Status, source.DateTime)\r\n            else switch item.State\r\n                when \"ok\" then target.Set(\"ok_normal\", source.Status, source.DateTime)\r\n                when \"error\" then target.Set(\"error_defective\", source.Status, source.DateTime)\r\n                when \"alarm\" then target.Set(\"alarm_alarm\", source.Status, source.DateTime)\r\n                when \"none\" then target.Set(\"none_unknown\", source.Status, source.DateTime)\r\n                else target.Set(\"DEFAULT\", Status.invalid, source.DateTime)\r\n        now\r\n    end\r\n\r\n    let proxy = @object as ProxyType\r\n    if (proxy isnt nil) and (\"command\" in changes) then\r\n        let source = proxy[\"command\"].Old ?? proxy[\"command\"]\r\n        from proxy.(settings.proxy_pin).GetOppositeItems() where it is ItemType do \r\n            let target = it[\"command\"]\r\n            if source.Text in target.EnumNames then target.Set(source.Text, source.Status, source.DateTime) \r\n            else target.Set(\"DEFAULT\", Status.invalid, source.DateTime)\r\n        now\r\n    end\r\nend\r\n","datetime":1555660299,"status":null,"version":0},"name":{"value":"Proxy item 3","datetime":1555659092,"status":null,"version":0}},"entity":"item","operation":"create"}]