Reconnect and device name fix for harmony platform (#20108)

* Update requirements

Updated requirements

* Add attributes

Add firmware and config version attributes

* Small bump for aioharmony

Small version bump increase for aioharmony

* Fix requirements file

For some reason aioharmony ended up in there as a duplicate. Fixed it.

* Fix for send command with named device

* Update requirements to get reconnect fix

* Set aioharmony version to 0.1.4

Version 0.1.4 has additional small fixes.

* Keep trying to connect on startup

Keep trying to connect to the HUB on startup

* Revert rebase changes

Revert some changes that should have been reverted back as part of rebase.

* PlatformNotReady if unable to connect on startup

Will call PlatformNotReady if unable to connect to Hub on startup

* Increase aioharmony requirement to 0.1.5

Increase aioharmony requirement to 0.1.5

* Register callbacks when entity added to HASS

Register the callbacks only once the entity has been added to HASS instead of during setup of platform.

* Removed debug log in __init__

Removed debug log in __init__
pull/20152/head
ehendrix23 2019-01-16 00:35:29 -07:00 committed by Martin Hjelmare
parent 19e19009cc
commit 78da6828f0
2 changed files with 40 additions and 27 deletions

View File

@ -22,7 +22,7 @@ import homeassistant.helpers.config_validation as cv
from homeassistant.exceptions import PlatformNotReady
from homeassistant.util import slugify
REQUIREMENTS = ['aioharmony==0.1.2']
REQUIREMENTS = ['aioharmony==0.1.5']
_LOGGER = logging.getLogger(__name__)
@ -106,6 +106,9 @@ async def async_setup_platform(hass, config, async_add_entities,
try:
device = HarmonyRemote(
name, address, port, activity, harmony_conf_file, delay_secs)
if not await device.connect():
raise PlatformNotReady
DEVICES.append(device)
async_add_entities([device])
register_services(hass)
@ -152,33 +155,36 @@ class HarmonyRemote(remote.RemoteDevice):
def __init__(self, name, host, port, activity, out_path, delay_secs):
"""Initialize HarmonyRemote class."""
from aioharmony.harmonyapi import (
HarmonyAPI as HarmonyClient, ClientCallbackType
)
from aioharmony.harmonyapi import HarmonyAPI as HarmonyClient
_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 = HarmonyClient(
ip_address=host,
callbacks=ClientCallbackType(
new_activity=self.new_activity,
config_updated=self.new_config,
connect=self.got_connected,
disconnect=self.got_disconnected
)
)
self._client = HarmonyClient(ip_address=host)
self._config_path = out_path
self._delay_secs = delay_secs
self._available = False
async def async_added_to_hass(self):
"""Complete the initialization."""
from aioharmony.harmonyapi import ClientCallbackType
_LOGGER.debug("%s: Harmony Hub added", self._name)
# Register the callbacks
self._client.callbacks = ClientCallbackType(
new_activity=self.new_activity,
config_updated=self.new_config,
connect=self.got_connected,
disconnect=self.got_disconnected
)
# Store Harmony HUB config, this will also update our current
# activity
await self.new_config()
import aioharmony.exceptions as aioexc
async def shutdown(_):
@ -191,15 +197,6 @@ class HarmonyRemote(remote.RemoteDevice):
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, shutdown)
_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):
"""Return the Harmony device's name."""
@ -225,6 +222,22 @@ class HarmonyRemote(remote.RemoteDevice):
"""Return True if connected to Hub, otherwise False."""
return self._available
async def connect(self):
"""Connect to the Harmony HUB."""
import aioharmony.exceptions as aioexc
_LOGGER.debug("%s: Connecting", self._name)
try:
if not await self._client.connect():
_LOGGER.warning("%s: Unable to connect to HUB.", self._name)
await self._client.close()
return False
except aioexc.TimeOut:
_LOGGER.warning("%s: Connection timed-out", self._name)
return False
return True
def new_activity(self, activity_info: tuple) -> None:
"""Call for updating the current activity."""
activity_id, activity_name = activity_info
@ -340,7 +353,7 @@ class HarmonyRemote(remote.RemoteDevice):
for _ in range(num_repeats):
for single_command in command:
send_command = SendCommandDevice(
device=device,
device=device_id,
command=single_command,
delay=0
)
@ -360,8 +373,8 @@ class HarmonyRemote(remote.RemoteDevice):
"%s: %s",
result.command.command,
result.command.device,
result.command.code,
result.command.msg
result.code,
result.msg
)
async def change_channel(self, channel):

View File

@ -105,7 +105,7 @@ aiofreepybox==0.0.6
aioftp==0.12.0
# homeassistant.components.remote.harmony
aioharmony==0.1.2
aioharmony==0.1.5
# homeassistant.components.emulated_hue
# homeassistant.components.http