From f1fcf49602871aa65f7153d1640deebb68f4e070 Mon Sep 17 00:00:00 2001 From: Joe Keenan Date: Sat, 16 Jul 2022 10:26:50 -0400 Subject: [PATCH] Activity Device Fixes also added License file --- HarmonyHub.indigoPlugin/Contents/Info.plist | 2 +- .../Contents/Server Plugin/plugin.py | 20 +++++++++++++----- LICENSE | 21 +++++++++++++++++++ README.md | 7 ++++--- 4 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 LICENSE diff --git a/HarmonyHub.indigoPlugin/Contents/Info.plist b/HarmonyHub.indigoPlugin/Contents/Info.plist index d579abc..d60c09c 100644 --- a/HarmonyHub.indigoPlugin/Contents/Info.plist +++ b/HarmonyHub.indigoPlugin/Contents/Info.plist @@ -3,7 +3,7 @@ PluginVersion - 2022.0.0 + 2022.0.1 ServerApiVersion 3.0 IwsApiVersion diff --git a/HarmonyHub.indigoPlugin/Contents/Server Plugin/plugin.py b/HarmonyHub.indigoPlugin/Contents/Server Plugin/plugin.py index d07a096..3f5af5c 100644 --- a/HarmonyHub.indigoPlugin/Contents/Server Plugin/plugin.py +++ b/HarmonyHub.indigoPlugin/Contents/Server Plugin/plugin.py @@ -13,7 +13,7 @@ from aioharmony.responsehandler import Handler from aioharmony.const import ClientCallbackType, WEBSOCKETS, XMPP except ImportError: - raise ImportError("'Required Python libraries missing. Run 'pip3 install aioharmony' in Terminal window, then reload plugin.") + raise ImportError("'Required Python libraries missing. Run 'pip3 install aioharmony' in Terminal window, then reload plugin. Xcode required!") class Listener(object): @@ -80,7 +80,8 @@ def deviceStartComm(self, device): self._event_loop.create_task(self._async_start_device(device)) self.hub_devices[device.id] = device elif device.deviceTypeId == "activityDevice": - self.activity_devices[device.id] = device + self.activity_devices[device.id] = device.pluginProps['activity'] + else: self.logger.error(f"{device.name}: deviceStartComm - Unknown device type: {device.deviceTypeId}") @@ -91,7 +92,7 @@ def deviceStopComm(self, device): self._event_loop.create_task(self._async_stop_device(device.address)) self.hub_devices.pop(device.id, None) elif device.deviceTypeId == "activityDevice": - self.hub_devices.pop(device.id, None) + self.activity_devices.pop(device.id, None) else: self.logger.error(f"{device.name}: deviceStopComm - Unknown device type: {device.deviceTypeId}") @@ -156,7 +157,7 @@ def powerOff(self, pluginAction): def doActivity(self, deviceId, activityID): self.logger.debug(f"Sending activity {activityID} to hub device {deviceId}") - client = self._async_running_clients[self.hub_devices[deviceId].address] + client = self._async_running_clients[self.hub_devices[int(deviceId)].address] self._event_loop.create_task(self.start_activity(client, int(activityID))) ######################################## @@ -503,6 +504,16 @@ def message_handler(self, message): elif message_type == "harmony.engine?startActivityFinished": self.logger.debug(f"{hub_device.name}: Event startActivityFinished, activityId = {message['data']['activityId']}, errorCode = {message['data']['errorCode']}, errorString = {message['data']['errorString']}") + + # update the activity devices + for deviceId, activityId in self.activity_devices.items(): + device = indigo.devices[deviceId] + if activityId == message['data']['activityId']: + device.updateStateOnServer(key='onOffState', value=True) + else: + device.updateStateOnServer(key='onOffState', value=False) + + # Update the hub's state and send the event to any subscribers config = self._async_running_clients[hub_device.address].config for activity in config["activity"]: if message['data']['activityId'] == activity['id']: @@ -593,4 +604,3 @@ async def send_command(self, client, device_id, command, delay=0): f"HUB: {client.name} Sending of command {result.command.command} to device {result.command.device} failed with code {result.code}: {result.msg}") else: self.logger.debug(f"{client.name}: '{command}' command sent") - diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..99e483d --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Joe Keenan + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 387b40c..aed6baa 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ This plugin enables monitoring of certain activities on the Harmony Hub, and pro | Requirement | | |------------------------|------------| | Minimum Indigo Version | 2022.1 | -| Python Library (API) | Unofficial | +| Python Library (API) | Unofficial | | Requires Local Network | Yes | | Requires Internet | No | | Hardware Interface | None | @@ -15,12 +15,13 @@ This plugin enables monitoring of certain activities on the Harmony Hub, and pro ## Installation Instructions +This plugin uses compiled Python3 libraries. You must have Xcode installed to install these libraries. + In Terminal.app enter: `pip3 install aioharmony` -The plugin an use either WebSockets or XMPP for communication with the Hubs. The default is WebSockets, but can be changed in the plugin Preferences dialog. -Use of automation notifications require XMPP. See https://support.logi.com/hc/en-001/community/posts/360032837213-Update-to-accessing-Harmony-Hub-s-local-API-via-XMPP +The plugin can use either WebSockets or XMPP for communication with the Hubs. The default is WebSockets, but can be changed in the plugin Preferences dialog. See https://support.logi.com/hc/en-001/community/posts/360032837213-Update-to-accessing-Harmony-Hub-s-local-API-via-XMPP for instructions.