Xiaomi MiIO Remote: Unique id added (#13266)

* Unique id added.

* Provide the exception as "ex"
pull/13281/head
Sebastian Muszynski 2018-03-16 21:15:23 +01:00 committed by Teemu R
parent 88d2a6ab80
commit ed6cd0ccfa
1 changed files with 20 additions and 7 deletions

View File

@ -18,6 +18,7 @@ from homeassistant.components.remote import (
from homeassistant.const import (
CONF_NAME, CONF_HOST, CONF_TOKEN, CONF_TIMEOUT,
ATTR_ENTITY_ID, ATTR_HIDDEN, CONF_COMMAND)
from homeassistant.exceptions import PlatformNotReady
import homeassistant.helpers.config_validation as cv
from homeassistant.util.dt import utcnow
@ -78,10 +79,16 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
# Check that we can communicate with device.
try:
device.info()
device_info = device.info()
model = device_info.model
unique_id = "{}-{}".format(model, device_info.mac_address)
_LOGGER.info("%s %s %s detected",
model,
device_info.firmware_version,
device_info.hardware_version)
except DeviceException as ex:
_LOGGER.error("Token not accepted by device : %s", ex)
return
_LOGGER.error("Device unavailable or token incorrect: %s", ex)
raise PlatformNotReady
if DATA_KEY not in hass.data:
hass.data[DATA_KEY] = {}
@ -93,9 +100,9 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
hidden = config.get(ATTR_HIDDEN)
xiaomi_miio_remote = XiaomiMiioRemote(
friendly_name, device, slot, timeout,
hidden, config.get(CONF_COMMANDS))
xiaomi_miio_remote = XiaomiMiioRemote(friendly_name, device, unique_id,
slot, timeout, hidden,
config.get(CONF_COMMANDS))
hass.data[DATA_KEY][host] = xiaomi_miio_remote
@ -158,17 +165,23 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
class XiaomiMiioRemote(RemoteDevice):
"""Representation of a Xiaomi Miio Remote device."""
def __init__(self, friendly_name, device,
def __init__(self, friendly_name, device, unique_id,
slot, timeout, hidden, commands):
"""Initialize the remote."""
self._name = friendly_name
self._device = device
self._unique_id = unique_id
self._is_hidden = hidden
self._slot = slot
self._timeout = timeout
self._state = False
self._commands = commands
@property
def unique_id(self):
"""Return an unique ID."""
return self._unique_id
@property
def name(self):
"""Return the name of the remote."""