Skip to content

Commit

Permalink
Activity Device Fixes
Browse files Browse the repository at this point in the history
also added License file
  • Loading branch information
FlyingDiver committed Jul 16, 2022
1 parent aedd42b commit f1fcf49
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
2 changes: 1 addition & 1 deletion HarmonyHub.indigoPlugin/Contents/Info.plist
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>PluginVersion</key>
<string>2022.0.0</string>
<string>2022.0.1</string>
<key>ServerApiVersion</key>
<string>3.0</string>
<key>IwsApiVersion</key>
Expand Down
20 changes: 15 additions & 5 deletions HarmonyHub.indigoPlugin/Contents/Server Plugin/plugin.py
Expand Up @@ -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):

Expand Down Expand Up @@ -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}")

Expand All @@ -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}")

Expand Down Expand Up @@ -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)))

########################################
Expand Down Expand Up @@ -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']:
Expand Down Expand Up @@ -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")

21 changes: 21 additions & 0 deletions 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.
7 changes: 4 additions & 3 deletions README.md
Expand Up @@ -7,20 +7,21 @@ 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 |


## 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.


Expand Down

0 comments on commit f1fcf49

Please sign in to comment.