mirror of
https://github.com/home-assistant/core.git
synced 2025-08-13 17:45:19 +02:00
Unique id added.
This commit is contained in:
@@ -325,12 +325,14 @@ async def async_setup_platform(hass, config, async_add_devices,
|
|||||||
model = config.get(CONF_MODEL)
|
model = config.get(CONF_MODEL)
|
||||||
|
|
||||||
_LOGGER.info("Initializing with host %s (token %s...)", host, token[:5])
|
_LOGGER.info("Initializing with host %s (token %s...)", host, token[:5])
|
||||||
|
unique_id = None
|
||||||
|
|
||||||
if model is None:
|
if model is None:
|
||||||
try:
|
try:
|
||||||
miio_device = Device(host, token)
|
miio_device = Device(host, token)
|
||||||
device_info = miio_device.info()
|
device_info = miio_device.info()
|
||||||
model = device_info.model
|
model = device_info.model
|
||||||
|
unique_id = "{}-{}".format(model, device_info.mac_address)
|
||||||
_LOGGER.info("%s %s %s detected",
|
_LOGGER.info("%s %s %s detected",
|
||||||
model,
|
model,
|
||||||
device_info.firmware_version,
|
device_info.firmware_version,
|
||||||
@@ -341,11 +343,11 @@ async def async_setup_platform(hass, config, async_add_devices,
|
|||||||
if model.startswith('zhimi.airpurifier.'):
|
if model.startswith('zhimi.airpurifier.'):
|
||||||
from miio import AirPurifier
|
from miio import AirPurifier
|
||||||
air_purifier = AirPurifier(host, token)
|
air_purifier = AirPurifier(host, token)
|
||||||
device = XiaomiAirPurifier(name, air_purifier, model)
|
device = XiaomiAirPurifier(name, air_purifier, model, unique_id)
|
||||||
elif model.startswith('zhimi.humidifier.'):
|
elif model.startswith('zhimi.humidifier.'):
|
||||||
from miio import AirHumidifier
|
from miio import AirHumidifier
|
||||||
air_humidifier = AirHumidifier(host, token)
|
air_humidifier = AirHumidifier(host, token)
|
||||||
device = XiaomiAirHumidifier(name, air_humidifier, model)
|
device = XiaomiAirHumidifier(name, air_humidifier, model, unique_id)
|
||||||
else:
|
else:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
'Unsupported device found! Please create an issue at '
|
'Unsupported device found! Please create an issue at '
|
||||||
@@ -386,11 +388,12 @@ async def async_setup_platform(hass, config, async_add_devices,
|
|||||||
class XiaomiGenericDevice(FanEntity):
|
class XiaomiGenericDevice(FanEntity):
|
||||||
"""Representation of a generic Xiaomi device."""
|
"""Representation of a generic Xiaomi device."""
|
||||||
|
|
||||||
def __init__(self, name, device, model):
|
def __init__(self, name, device, model, unique_id):
|
||||||
"""Initialize the generic Xiaomi device."""
|
"""Initialize the generic Xiaomi device."""
|
||||||
self._name = name
|
self._name = name
|
||||||
self._device = device
|
self._device = device
|
||||||
self._model = model
|
self._model = model
|
||||||
|
self._unique_id = unique_id
|
||||||
self._state = None
|
self._state = None
|
||||||
self._state_attrs = {
|
self._state_attrs = {
|
||||||
ATTR_MODEL: self._model,
|
ATTR_MODEL: self._model,
|
||||||
@@ -408,6 +411,11 @@ class XiaomiGenericDevice(FanEntity):
|
|||||||
"""Poll the device."""
|
"""Poll the device."""
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@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 device if any."""
|
"""Return the name of the device if any."""
|
||||||
@@ -550,9 +558,9 @@ class XiaomiGenericDevice(FanEntity):
|
|||||||
class XiaomiAirPurifier(XiaomiGenericDevice):
|
class XiaomiAirPurifier(XiaomiGenericDevice):
|
||||||
"""Representation of a Xiaomi Air Purifier."""
|
"""Representation of a Xiaomi Air Purifier."""
|
||||||
|
|
||||||
def __init__(self, name, device, model):
|
def __init__(self, name, device, model, unique_id):
|
||||||
"""Initialize the plug switch."""
|
"""Initialize the plug switch."""
|
||||||
XiaomiGenericDevice.__init__(self, name, device, model)
|
XiaomiGenericDevice.__init__(self, name, device, model, unique_id)
|
||||||
|
|
||||||
if self._model == MODEL_AIRPURIFIER_PRO:
|
if self._model == MODEL_AIRPURIFIER_PRO:
|
||||||
self._additional_supported_features = SUPPORT_FLAGS_AIRPURIFIER_PRO
|
self._additional_supported_features = SUPPORT_FLAGS_AIRPURIFIER_PRO
|
||||||
@@ -744,9 +752,9 @@ class XiaomiAirPurifier(XiaomiGenericDevice):
|
|||||||
class XiaomiAirHumidifier(XiaomiGenericDevice):
|
class XiaomiAirHumidifier(XiaomiGenericDevice):
|
||||||
"""Representation of a Xiaomi Air Humidifier."""
|
"""Representation of a Xiaomi Air Humidifier."""
|
||||||
|
|
||||||
def __init__(self, name, device, model):
|
def __init__(self, name, device, model, unique_id):
|
||||||
"""Initialize the plug switch."""
|
"""Initialize the plug switch."""
|
||||||
XiaomiGenericDevice.__init__(self, name, device, model)
|
XiaomiGenericDevice.__init__(self, name, device, model, unique_id)
|
||||||
|
|
||||||
self._additional_supported_features = SUPPORT_FLAGS_AIRHUMIDIFIER
|
self._additional_supported_features = SUPPORT_FLAGS_AIRHUMIDIFIER
|
||||||
self._state_attrs.update({attribute: None for attribute in
|
self._state_attrs.update({attribute: None for attribute in
|
||||||
|
Reference in New Issue
Block a user