Xiaomi MiIO Remote: Unique id added (#13266)
* Unique id added. * Provide the exception as "ex"pull/13281/head
parent
88d2a6ab80
commit
ed6cd0ccfa
|
@ -18,6 +18,7 @@ from homeassistant.components.remote import (
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_NAME, CONF_HOST, CONF_TOKEN, CONF_TIMEOUT,
|
CONF_NAME, CONF_HOST, CONF_TOKEN, CONF_TIMEOUT,
|
||||||
ATTR_ENTITY_ID, ATTR_HIDDEN, CONF_COMMAND)
|
ATTR_ENTITY_ID, ATTR_HIDDEN, CONF_COMMAND)
|
||||||
|
from homeassistant.exceptions import PlatformNotReady
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.util.dt import utcnow
|
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.
|
# Check that we can communicate with device.
|
||||||
try:
|
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:
|
except DeviceException as ex:
|
||||||
_LOGGER.error("Token not accepted by device : %s", ex)
|
_LOGGER.error("Device unavailable or token incorrect: %s", ex)
|
||||||
return
|
raise PlatformNotReady
|
||||||
|
|
||||||
if DATA_KEY not in hass.data:
|
if DATA_KEY not in hass.data:
|
||||||
hass.data[DATA_KEY] = {}
|
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)
|
hidden = config.get(ATTR_HIDDEN)
|
||||||
|
|
||||||
xiaomi_miio_remote = XiaomiMiioRemote(
|
xiaomi_miio_remote = XiaomiMiioRemote(friendly_name, device, unique_id,
|
||||||
friendly_name, device, slot, timeout,
|
slot, timeout, hidden,
|
||||||
hidden, config.get(CONF_COMMANDS))
|
config.get(CONF_COMMANDS))
|
||||||
|
|
||||||
hass.data[DATA_KEY][host] = xiaomi_miio_remote
|
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):
|
class XiaomiMiioRemote(RemoteDevice):
|
||||||
"""Representation of a Xiaomi Miio Remote device."""
|
"""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):
|
slot, timeout, hidden, commands):
|
||||||
"""Initialize the remote."""
|
"""Initialize the remote."""
|
||||||
self._name = friendly_name
|
self._name = friendly_name
|
||||||
self._device = device
|
self._device = device
|
||||||
|
self._unique_id = unique_id
|
||||||
self._is_hidden = hidden
|
self._is_hidden = hidden
|
||||||
self._slot = slot
|
self._slot = slot
|
||||||
self._timeout = timeout
|
self._timeout = timeout
|
||||||
self._state = False
|
self._state = False
|
||||||
self._commands = commands
|
self._commands = commands
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unique_id(self):
|
||||||
|
"""Return an unique ID."""
|
||||||
|
return self._unique_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the remote."""
|
"""Return the name of the remote."""
|
||||||
|
|
Loading…
Reference in New Issue