From cbc656549c0ed1d3c29984afb01b6d487b439c79 Mon Sep 17 00:00:00 2001 From: Erik Hendrix Date: Wed, 26 Dec 2018 12:52:22 -0700 Subject: [PATCH 1/8] Use aioharmony for async Use aioharmony to interact with Harmony hub. Due to this following improvements: -) Setting of available state for entity -) Automatic config update if configuration changes (including updating file containing config) -) Allow using of device name instead of number -) When sending command with repeat, nothing else will be able to put a IR command in between --- homeassistant/components/remote/harmony.py | 140 +++++++++++++++------ 1 file changed, 104 insertions(+), 36 deletions(-) diff --git a/homeassistant/components/remote/harmony.py b/homeassistant/components/remote/harmony.py index 0200a6840993da..0eded2d4a2faf3 100644 --- a/homeassistant/components/remote/harmony.py +++ b/homeassistant/components/remote/harmony.py @@ -24,9 +24,8 @@ # REQUIREMENTS = ['pyharmony==1.0.22'] REQUIREMENTS = [ - 'https://github.com/home-assistant/pyharmony/archive/' - '31efd339a3c39e7b8f58e823a0eddb59013e03ae.zip' - '#pyharmony==1.0.21b1' + 'https://github.com/ehendrix23/aioharmony/archive/dev.zip#aioharmony==0' + '.0.5' ] _LOGGER = logging.getLogger(__name__) @@ -142,7 +141,9 @@ class HarmonyRemote(remote.RemoteDevice): def __init__(self, name, host, port, activity, out_path, delay_secs): """Initialize HarmonyRemote class.""" - import pyharmony.client as harmony_client + from aioharmony.harmonyapi import ( + HarmonyAPI as harmony_client, ClientCallbackType) + _LOGGER.debug("HarmonyRemote device init started for: %s", name) self._name = name @@ -151,10 +152,18 @@ def __init__(self, name, host, port, activity, out_path, delay_secs): self._state = None self._current_activity = None self._default_activity = activity - # self._client = pyharmony.get_client(host, port, self.new_activity) - self._client = harmony_client.HarmonyClient(host) + self._client = harmony_client( + ip_address=host, + callbacks=ClientCallbackType( + new_activity=self.new_activity, + config_updated=self.new_config, + connect=self.got_connected, + disconnect=self.got_disconnected + ) + ) self._config_path = out_path self._delay_secs = delay_secs + self._available = True _LOGGER.debug("HarmonyRemote device init completed for: %s", name) async def async_added_to_hass(self): @@ -163,18 +172,17 @@ async def async_added_to_hass(self): async def shutdown(event): """Close connection on shutdown.""" - await self._client.disconnect() + await self._client.close() self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, shutdown) _LOGGER.debug("Connecting.") await self._client.connect() - await self._client.get_config() if not Path(self._config_path).is_file(): - self.write_config_file() + await self.hass.async_add_executor_job(self.write_config_file) # Poll for initial state - self.new_activity(await self._client.get_current_activity()) + self.new_activity(self._client.current_activity) @property def name(self): @@ -184,7 +192,7 @@ def name(self): @property def should_poll(self): """Return the fact that we should not be polled.""" - return True + return False @property def device_state_attributes(self): @@ -196,101 +204,161 @@ def is_on(self): """Return False if PowerOff is the current activity, otherwise True.""" return self._current_activity not in [None, 'PowerOff'] + @property + def available(self): + return self._available + async def async_update(self): """Retrieve current activity from Hub.""" _LOGGER.debug("Updating Harmony.") if not self._client.config: await self._client.get_config() - activity_id = await self._client.get_current_activity() - activity_name = self._client.get_activity_name(activity_id) + activity_id, activity_name = self._client.current_activity _LOGGER.debug("%s activity reported as: %s", self._name, activity_name) self._current_activity = activity_name self._state = bool(self._current_activity != 'PowerOff') return - def new_activity(self, activity_id): + def new_activity(self, activity_info): """Call for updating the current activity.""" - activity_name = self._client.get_activity_name(activity_id) + activity_id, activity_name = activity_info _LOGGER.debug("%s activity reported as: %s", self._name, activity_name) self._current_activity = activity_name self._state = bool(self._current_activity != 'PowerOff') self.schedule_update_ha_state() + def new_config(self, _ = None): + """Call for updating the current activity.""" + _LOGGER.debug("%s configuration has been updated", self._name) + self.new_activity(self._client.current_activity) + + _, self._current_activity = self._client.current_activity + self._state = bool(self._current_activity != 'PowerOff') + self.schedule_update_ha_state() + self.write_config_file() + + def got_connected(self, _ = None): + """Notification that we're connected to the HUB.""" + _LOGGER.debug("%s connected to the HUB.", self._name) + if not self._available: + # We were disconnected before. + self.new_config() + self._available = True + + async def got_disconnected(self, _ = None): + """Notification that we're disconnected from the HUB.""" + _LOGGER.debug("%s disconnected from the HUB.", self._name) + self._available = False + # We're going to wait for 10 seconds before announcing we're + # unavailable, this to allow a reconnection to happen. + await asyncio.sleep(10) + + if not self._available: + # Still disconnected. Let the state engine know. + self.schedule_update_ha_state() + async def async_turn_on(self, **kwargs): """Start an activity from the Harmony device.""" + _LOGGER.debug("%s: Turn On", self.name) activity = kwargs.get(ATTR_ACTIVITY, self._default_activity) if activity: activity_id = None if activity.isdigit() or activity == '-1': - _LOGGER.debug("Activity is numeric") + _LOGGER.debug("%s: Activity is numeric", self.name) if self._client.get_activity_name(int(activity)): activity_id = activity - if not activity_id: - _LOGGER.debug("Find activity ID based on name") + if activity_id is None: + _LOGGER.debug("%s: Find activity ID based on name", self.name) activity_id = self._client.get_activity_id( str(activity).strip()) - if not activity_id: - _LOGGER.error("Activity %s is invalid", activity) + if activity_id is None: + _LOGGER.error("%s: Activity %s is invalid", + self.name, activity) return await self._client.start_activity(activity_id) self._state = True else: - _LOGGER.error("No activity specified with turn_on service") + _LOGGER.error("%s: No activity specified with turn_on service", + self.name) async def async_turn_off(self, **kwargs): """Start the PowerOff activity.""" + _LOGGER.debug("%s: Turn Off", self.name) await self._client.power_off() # pylint: disable=arguments-differ async def async_send_command(self, command, **kwargs): """Send a list of commands to one device.""" + from aioharmony.harmonyapi import SendCommandDevice + _LOGGER.debug("%s: Send Command", self.name) device = kwargs.get(ATTR_DEVICE) if device is None: - _LOGGER.error("Missing required argument: device") + _LOGGER.error("%s: Missing required argument: device", self.name) return device_id = None if device.isdigit(): - _LOGGER.debug("Device is numeric") + _LOGGER.debug("%s: Device %s is numeric", + self.name, device) if self._client.get_device_name(int(device)): device_id = device - if not device_id: - _LOGGER.debug("Find device ID based on device name") - device_id = self._client.get_activity_id(str(device).strip()) + if device_id is None: + _LOGGER.debug("%s: Find device ID %s based on device name", + self.name, device) + device_id = self._client.get_device_id(str(device).strip()) - if not device_id: - _LOGGER.error("Device %s is invalid", device) + if device_id is None: + _LOGGER.error("%s: Device %s is invalid", self.name, device) return num_repeats = kwargs.get(ATTR_NUM_REPEATS) delay_secs = kwargs.get(ATTR_DELAY_SECS, self._delay_secs) + # Creating list of commands to send. + snd_cmnd_list = [] for _ in range(num_repeats): for single_command in command: - _LOGGER.debug("Sending command %s", single_command) - await self._client.send_command(device, single_command) - await asyncio.sleep(delay_secs) + send_command = SendCommandDevice( + device=device, + command=single_command, + delay=0 + ) + snd_cmnd_list.append(send_command) + if delay_secs > 0: + snd_cmnd_list.append(float(delay_secs)) + + _LOGGER.debug("%s: Sending commands", self.name) + result_list = await self._client.send_commands(snd_cmnd_list) + for result in result_list: + _LOGGER.warning("Sending command %s to device %s failed with code " + "%s: %s", + result.command.command, + result.command.device, + result.command.code, + result.command.msg + ) async def sync(self): """Sync the Harmony device with the web service.""" - _LOGGER.debug("Syncing hub with Harmony servers") + _LOGGER.debug("%s: Syncing hub with Harmony servers", self.name) await self._client.sync() - await self._client.get_config() await self.hass.async_add_executor_job(self.write_config_file) def write_config_file(self): """Write Harmony configuration file.""" - _LOGGER.debug("Writing hub config to file: %s", self._config_path) + _LOGGER.debug("%s: Writing hub config to file: %s", + self.name, + self._config_path) try: with open(self._config_path, 'w+', encoding='utf-8') as file_out: json.dump(self._client.json_config, file_out, sort_keys=True, indent=4) except IOError as exc: - _LOGGER.error("Unable to write HUB configuration to %s: %s", - self._config_path, exc) + _LOGGER.error("%s: Unable to write HUB configuration to %s: %s", + self.name, self._config_path, exc) From 6b8ade5c3a49ae70e98171b5d34542e7ca0a7f47 Mon Sep 17 00:00:00 2001 From: Erik Hendrix Date: Wed, 26 Dec 2018 12:56:56 -0700 Subject: [PATCH 2/8] Requirements updated --- homeassistant/components/remote/harmony.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/remote/harmony.py b/homeassistant/components/remote/harmony.py index 0eded2d4a2faf3..1ba696f3fedac1 100644 --- a/homeassistant/components/remote/harmony.py +++ b/homeassistant/components/remote/harmony.py @@ -22,10 +22,10 @@ from homeassistant.exceptions import PlatformNotReady from homeassistant.util import slugify -# REQUIREMENTS = ['pyharmony==1.0.22'] +# REQUIREMENTS = ['aioharmony==0.1.00'] REQUIREMENTS = [ 'https://github.com/ehendrix23/aioharmony/archive/dev.zip#aioharmony==0' - '.0.5' + '.0.6' ] _LOGGER = logging.getLogger(__name__) From 6c17f514e42f045fc074c02e4130dfd96b6349f4 Mon Sep 17 00:00:00 2001 From: Erik Hendrix Date: Wed, 26 Dec 2018 13:48:44 -0700 Subject: [PATCH 3/8] Version update for fix --- homeassistant/components/remote/harmony.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/remote/harmony.py b/homeassistant/components/remote/harmony.py index 1ba696f3fedac1..20aac8668f0d35 100644 --- a/homeassistant/components/remote/harmony.py +++ b/homeassistant/components/remote/harmony.py @@ -25,7 +25,7 @@ # REQUIREMENTS = ['aioharmony==0.1.00'] REQUIREMENTS = [ 'https://github.com/ehendrix23/aioharmony/archive/dev.zip#aioharmony==0' - '.0.6' + '.0.7' ] _LOGGER = logging.getLogger(__name__) From 512ca26ef9f470cdf0462d1eb1963d1ab6ff5511 Mon Sep 17 00:00:00 2001 From: Erik Hendrix Date: Sat, 29 Dec 2018 14:31:08 -0700 Subject: [PATCH 4/8] Mainly cleanup --- homeassistant/components/remote/harmony.py | 158 +++++++++++---------- 1 file changed, 86 insertions(+), 72 deletions(-) diff --git a/homeassistant/components/remote/harmony.py b/homeassistant/components/remote/harmony.py index 20aac8668f0d35..920763ccf1fab5 100644 --- a/homeassistant/components/remote/harmony.py +++ b/homeassistant/components/remote/harmony.py @@ -7,31 +7,28 @@ import asyncio import json import logging -from datetime import timedelta -from pathlib import Path import voluptuous as vol from homeassistant.components import remote from homeassistant.components.remote import ( ATTR_ACTIVITY, ATTR_DELAY_SECS, ATTR_DEVICE, ATTR_NUM_REPEATS, - DEFAULT_DELAY_SECS, DOMAIN, PLATFORM_SCHEMA) + DEFAULT_DELAY_SECS, DOMAIN, PLATFORM_SCHEMA +) from homeassistant.const import ( - ATTR_ENTITY_ID, CONF_HOST, CONF_NAME, CONF_PORT, EVENT_HOMEASSISTANT_STOP) + ATTR_ENTITY_ID, CONF_HOST, CONF_NAME, CONF_PORT, EVENT_HOMEASSISTANT_STOP +) import homeassistant.helpers.config_validation as cv from homeassistant.exceptions import PlatformNotReady from homeassistant.util import slugify -# REQUIREMENTS = ['aioharmony==0.1.00'] -REQUIREMENTS = [ - 'https://github.com/ehendrix23/aioharmony/archive/dev.zip#aioharmony==0' - '.0.7' -] +REQUIREMENTS = ['aioharmony==0.1.00'] _LOGGER = logging.getLogger(__name__) +ATTR_CURRENT_ACTIVITY = 'current_activity' + DEFAULT_PORT = 8088 -SCAN_INTERVAL = timedelta(seconds=5) DEVICES = [] CONF_DEVICE_CACHE = 'harmony_device_cache' @@ -54,7 +51,6 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the Harmony platform.""" - host = None activity = None if CONF_DEVICE_CACHE not in hass.data: @@ -64,11 +60,11 @@ async def async_setup_platform(hass, config, async_add_entities, # Find the discovered device in the list of user configurations override = next((c for c in hass.data[CONF_DEVICE_CACHE] if c.get(CONF_NAME) == discovery_info.get(CONF_NAME)), - False) + None) port = DEFAULT_PORT delay_secs = DEFAULT_DELAY_SECS - if override: + if override is not None: activity = override.get(ATTR_ACTIVITY) delay_secs = override.get(ATTR_DELAY_SECS) port = override.get(CONF_PORT, DEFAULT_PORT) @@ -129,7 +125,6 @@ async def _apply_service(service, service_func, *service_func_args): for device in _devices: await service_func(device, *service_func_args) - device.schedule_update_ha_state(True) async def _sync_service(service): @@ -142,17 +137,17 @@ class HarmonyRemote(remote.RemoteDevice): def __init__(self, name, host, port, activity, out_path, delay_secs): """Initialize HarmonyRemote class.""" from aioharmony.harmonyapi import ( - HarmonyAPI as harmony_client, ClientCallbackType) - + HarmonyAPI as Harmony_Client, ClientCallbackType + ) - _LOGGER.debug("HarmonyRemote device init started for: %s", name) + _LOGGER.debug("%s: Device init started", name) self._name = name self.host = host self.port = port self._state = None self._current_activity = None self._default_activity = activity - self._client = harmony_client( + self._client = Harmony_Client( ip_address=host, callbacks=ClientCallbackType( new_activity=self.new_activity, @@ -163,26 +158,31 @@ def __init__(self, name, host, port, activity, out_path, delay_secs): ) self._config_path = out_path self._delay_secs = delay_secs - self._available = True - _LOGGER.debug("HarmonyRemote device init completed for: %s", name) + self._available = False async def async_added_to_hass(self): """Complete the initialization.""" - _LOGGER.debug("HarmonyRemote added for: %s", self._name) + _LOGGER.debug("%s: Harmony Hub added", self._name) + import aioharmony.exceptions as aioexc - async def shutdown(event): + async def shutdown(_): """Close connection on shutdown.""" - await self._client.close() + _LOGGER.debug("%s: Closing Harmony Hub", self._name) + try: + await self._client.close() + except aioexc.TimeOut: + _LOGGER.warning("%s: Disconnect timed-out", self._name) self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, shutdown) - _LOGGER.debug("Connecting.") - await self._client.connect() - if not Path(self._config_path).is_file(): - await self.hass.async_add_executor_job(self.write_config_file) - - # Poll for initial state - self.new_activity(self._client.current_activity) + _LOGGER.debug("%s: Connecting", self._name) + try: + await self._client.connect() + except aioexc.TimeOut: + _LOGGER.error("%s: Connection timed-out", self._name) + else: + # Set initial state + self.new_activity(self._client.current_activity) @property def name(self): @@ -197,7 +197,7 @@ def should_poll(self): @property def device_state_attributes(self): """Add platform specific attributes.""" - return {'current_activity': self._current_activity} + return {ATTR_CURRENT_ACTIVITY: self._current_activity} @property def is_on(self): @@ -208,47 +208,32 @@ def is_on(self): def available(self): return self._available - async def async_update(self): - """Retrieve current activity from Hub.""" - _LOGGER.debug("Updating Harmony.") - if not self._client.config: - await self._client.get_config() - - activity_id, activity_name = self._client.current_activity - _LOGGER.debug("%s activity reported as: %s", self._name, activity_name) - self._current_activity = activity_name - self._state = bool(self._current_activity != 'PowerOff') - return - - def new_activity(self, activity_info): + def new_activity(self, activity_info: tuple) -> None: """Call for updating the current activity.""" activity_id, activity_name = activity_info - _LOGGER.debug("%s activity reported as: %s", self._name, activity_name) + _LOGGER.debug("%s: activity reported as: %s", self._name, + activity_name) self._current_activity = activity_name - self._state = bool(self._current_activity != 'PowerOff') - self.schedule_update_ha_state() + self._state = bool(activity_id != -1) + self.async_schedule_update_ha_state() - def new_config(self, _ = None): + async def new_config(self, _=None): """Call for updating the current activity.""" - _LOGGER.debug("%s configuration has been updated", self._name) + _LOGGER.debug("%s: configuration has been updated", self._name) self.new_activity(self._client.current_activity) + await self.hass.async_add_executor_job(self.write_config_file) - _, self._current_activity = self._client.current_activity - self._state = bool(self._current_activity != 'PowerOff') - self.schedule_update_ha_state() - self.write_config_file() - - def got_connected(self, _ = None): + def got_connected(self, _=None): """Notification that we're connected to the HUB.""" - _LOGGER.debug("%s connected to the HUB.", self._name) + _LOGGER.debug("%s: connected to the HUB.", self._name) if not self._available: # We were disconnected before. self.new_config() self._available = True - async def got_disconnected(self, _ = None): + async def got_disconnected(self, _=None): """Notification that we're disconnected from the HUB.""" - _LOGGER.debug("%s disconnected from the HUB.", self._name) + _LOGGER.debug("%s: disconnected from the HUB.", self._name) self._available = False # We're going to wait for 10 seconds before announcing we're # unavailable, this to allow a reconnection to happen. @@ -256,11 +241,14 @@ async def got_disconnected(self, _ = None): if not self._available: # Still disconnected. Let the state engine know. - self.schedule_update_ha_state() + self.async_schedule_update_ha_state() async def async_turn_on(self, **kwargs): """Start an activity from the Harmony device.""" + import aioharmony.exceptions as aioexc + _LOGGER.debug("%s: Turn On", self.name) + activity = kwargs.get(ATTR_ACTIVITY, self._default_activity) if activity: @@ -280,21 +268,31 @@ async def async_turn_on(self, **kwargs): self.name, activity) return - await self._client.start_activity(activity_id) - self._state = True + try: + await self._client.start_activity(activity_id) + except aioexc.TimeOut: + _LOGGER.error("%s: Starting activity %s timed-out", + self.name, + activity) else: _LOGGER.error("%s: No activity specified with turn_on service", self.name) async def async_turn_off(self, **kwargs): """Start the PowerOff activity.""" + import aioharmony.exceptions as aioexc _LOGGER.debug("%s: Turn Off", self.name) - await self._client.power_off() + try: + await self._client.power_off() + except aioexc.TimeOut: + _LOGGER.error("%s: Powering off timed-out", self.name) # pylint: disable=arguments-differ async def async_send_command(self, command, **kwargs): """Send a list of commands to one device.""" from aioharmony.harmonyapi import SendCommandDevice + import aioharmony.exceptions as aioexc + _LOGGER.debug("%s: Send Command", self.name) device = kwargs.get(ATTR_DEVICE) if device is None: @@ -334,20 +332,31 @@ async def async_send_command(self, command, **kwargs): snd_cmnd_list.append(float(delay_secs)) _LOGGER.debug("%s: Sending commands", self.name) - result_list = await self._client.send_commands(snd_cmnd_list) + try: + result_list = await self._client.send_commands(snd_cmnd_list) + except aioexc.TimeOut: + _LOGGER.error("%s: Sending commands timed-out", self.name) + return + for result in result_list: - _LOGGER.warning("Sending command %s to device %s failed with code " - "%s: %s", - result.command.command, - result.command.device, - result.command.code, - result.command.msg - ) + _LOGGER.error("Sending command %s to device %s failed with code " + "%s: %s", + result.command.command, + result.command.device, + result.command.code, + result.command.msg + ) async def sync(self): """Sync the Harmony device with the web service.""" - _LOGGER.debug("%s: Syncing hub with Harmony servers", self.name) - await self._client.sync() + import aioharmony.exceptions as aioexc + + _LOGGER.debug("%s: Syncing hub with Harmony cloud", self.name) + try: + await self._client.sync() + except aioexc.TimeOut: + _LOGGER.error("%s: Syncing hub with Harmony cloud timed-out", + self.name) await self.hass.async_add_executor_job(self.write_config_file) def write_config_file(self): @@ -355,6 +364,11 @@ def write_config_file(self): _LOGGER.debug("%s: Writing hub config to file: %s", self.name, self._config_path) + if self._client.config is None: + _LOGGER.warning("%s: No configuration received from hub", + self.name) + return + try: with open(self._config_path, 'w+', encoding='utf-8') as file_out: json.dump(self._client.json_config, file_out, From e4201595b1f39e9ce9f1abcf2e3020d89c25700a Mon Sep 17 00:00:00 2001 From: Erik Hendrix Date: Sat, 29 Dec 2018 15:14:38 -0700 Subject: [PATCH 5/8] Update requirements Updated requirements --- requirements_all.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/requirements_all.txt b/requirements_all.txt index 1a3698a63101eb..b4aebf6232c0d4 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -104,6 +104,9 @@ aiofreepybox==0.0.5 # homeassistant.components.camera.yi aioftp==0.10.1 +# homeassistant.components.remote.harmony +aioharmony==0.1.00 + # homeassistant.components.emulated_hue # homeassistant.components.http aiohttp_cors==0.7.0 @@ -520,9 +523,6 @@ homematicip==0.9.8 # homeassistant.components.remember_the_milk httplib2==0.10.3 -# homeassistant.components.remote.harmony -https://github.com/home-assistant/pyharmony/archive/31efd339a3c39e7b8f58e823a0eddb59013e03ae.zip#pyharmony==1.0.21b1 - # homeassistant.components.huawei_lte huawei-lte-api==1.0.16 From def1ab45fa89b0ff8945ab66b3893d470148beef Mon Sep 17 00:00:00 2001 From: Erik Hendrix Date: Sat, 29 Dec 2018 16:10:06 -0700 Subject: [PATCH 6/8] Fixed lint issue --- homeassistant/components/remote/harmony.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/remote/harmony.py b/homeassistant/components/remote/harmony.py index 920763ccf1fab5..cf58be12db4f4f 100644 --- a/homeassistant/components/remote/harmony.py +++ b/homeassistant/components/remote/harmony.py @@ -206,6 +206,7 @@ def is_on(self): @property def available(self): + """Return True if connected to Hub, otherwise False.""" return self._available def new_activity(self, activity_info: tuple) -> None: From 60e98ab9eaca7663ec456029a73bd5e88f4cecb1 Mon Sep 17 00:00:00 2001 From: Erik Hendrix Date: Sat, 29 Dec 2018 16:34:30 -0700 Subject: [PATCH 7/8] Small bump for aioharmony Small version bump increase for aioharmony --- homeassistant/components/remote/harmony.py | 2 +- requirements_all.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/remote/harmony.py b/homeassistant/components/remote/harmony.py index cf58be12db4f4f..cc2af5bc127568 100644 --- a/homeassistant/components/remote/harmony.py +++ b/homeassistant/components/remote/harmony.py @@ -22,7 +22,7 @@ from homeassistant.exceptions import PlatformNotReady from homeassistant.util import slugify -REQUIREMENTS = ['aioharmony==0.1.00'] +REQUIREMENTS = ['aioharmony==0.1.1'] _LOGGER = logging.getLogger(__name__) diff --git a/requirements_all.txt b/requirements_all.txt index b4aebf6232c0d4..ea28026eb48166 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -105,7 +105,7 @@ aiofreepybox==0.0.5 aioftp==0.10.1 # homeassistant.components.remote.harmony -aioharmony==0.1.00 +aioharmony==0.1.1 # homeassistant.components.emulated_hue # homeassistant.components.http From 1bcf916c4fa7da3c15d06f9e9a875f14bf2f9023 Mon Sep 17 00:00:00 2001 From: Erik Hendrix Date: Sat, 29 Dec 2018 17:01:42 -0700 Subject: [PATCH 8/8] Updated based on review --- homeassistant/components/remote/harmony.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/remote/harmony.py b/homeassistant/components/remote/harmony.py index cc2af5bc127568..aeb3d85d91c499 100644 --- a/homeassistant/components/remote/harmony.py +++ b/homeassistant/components/remote/harmony.py @@ -137,7 +137,7 @@ class HarmonyRemote(remote.RemoteDevice): def __init__(self, name, host, port, activity, out_path, delay_secs): """Initialize HarmonyRemote class.""" from aioharmony.harmonyapi import ( - HarmonyAPI as Harmony_Client, ClientCallbackType + HarmonyAPI as HarmonyClient, ClientCallbackType ) _LOGGER.debug("%s: Device init started", name) @@ -147,7 +147,7 @@ def __init__(self, name, host, port, activity, out_path, delay_secs): self._state = None self._current_activity = None self._default_activity = activity - self._client = Harmony_Client( + self._client = HarmonyClient( ip_address=host, callbacks=ClientCallbackType( new_activity=self.new_activity, @@ -358,7 +358,8 @@ async def sync(self): except aioexc.TimeOut: _LOGGER.error("%s: Syncing hub with Harmony cloud timed-out", self.name) - await self.hass.async_add_executor_job(self.write_config_file) + else: + await self.hass.async_add_executor_job(self.write_config_file) def write_config_file(self): """Write Harmony configuration file."""