Small clean up for Motion Blinds (#52281)

This commit is contained in:
Franck Nijhof 2021-06-29 13:08:19 +02:00 committed by GitHub
parent c785db4ffa
commit 3311b1bafb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 107 deletions

View File

@ -80,12 +80,7 @@ class DataUpdateCoordinatorMotionBlinds(DataUpdateCoordinator):
"""Fetch the latest data from the gateway and blinds.""" """Fetch the latest data from the gateway and blinds."""
data = await self.hass.async_add_executor_job(self.update_gateway) data = await self.hass.async_add_executor_job(self.update_gateway)
all_available = True all_available = all(device[ATTR_AVAILABLE] for device in data.values())
for device in data.values():
if not device[ATTR_AVAILABLE]:
all_available = False
break
if all_available: if all_available:
self.update_interval = timedelta(seconds=UPDATE_INTERVAL) self.update_interval = timedelta(seconds=UPDATE_INTERVAL)
else: else:
@ -94,11 +89,6 @@ class DataUpdateCoordinatorMotionBlinds(DataUpdateCoordinator):
return data return data
def setup(hass: core.HomeAssistant, config: dict):
"""Set up the Motion Blinds component."""
return True
async def async_setup_entry( async def async_setup_entry(
hass: core.HomeAssistant, entry: config_entries.ConfigEntry hass: core.HomeAssistant, entry: config_entries.ConfigEntry
): ):

View File

@ -132,32 +132,19 @@ class MotionPositionDevice(CoordinatorEntity, CoverEntity):
super().__init__(coordinator) super().__init__(coordinator)
self._blind = blind self._blind = blind
self._device_class = device_class
self._config_entry = config_entry self._config_entry = config_entry
@property self._attr_device_class = device_class
def unique_id(self): self._attr_name = f"{blind.blind_type}-{blind.mac[12:]}"
"""Return the unique id of the blind.""" self._attr_unique_id = blind.mac
return self._blind.mac self._attr_device_info = {
"identifiers": {(DOMAIN, blind.mac)},
@property
def device_info(self):
"""Return the device info of the blind."""
device_info = {
"identifiers": {(DOMAIN, self._blind.mac)},
"manufacturer": MANUFACTURER, "manufacturer": MANUFACTURER,
"name": f"{self._blind.blind_type}-{self._blind.mac[12:]}", "name": f"{blind.blind_type}-{blind.mac[12:]}",
"model": self._blind.blind_type, "model": blind.blind_type,
"via_device": (DOMAIN, self._config_entry.unique_id), "via_device": (DOMAIN, config_entry.unique_id),
} }
return device_info
@property
def name(self):
"""Return the name of the blind."""
return f"{self._blind.blind_type}-{self._blind.mac[12:]}"
@property @property
def available(self): def available(self):
"""Return True if entity is available.""" """Return True if entity is available."""
@ -180,11 +167,6 @@ class MotionPositionDevice(CoordinatorEntity, CoverEntity):
return None return None
return 100 - self._blind.position return 100 - self._blind.position
@property
def device_class(self):
"""Return the device class."""
return self._device_class
@property @property
def is_closed(self): def is_closed(self):
"""Return if the cover is closed or not.""" """Return if the cover is closed or not."""
@ -263,20 +245,12 @@ class MotionTDBUDevice(MotionPositionDevice):
super().__init__(coordinator, blind, device_class, config_entry) super().__init__(coordinator, blind, device_class, config_entry)
self._motor = motor self._motor = motor
self._motor_key = motor[0] self._motor_key = motor[0]
self._attr_name = f"{blind.blind_type}-{motor}-{blind.mac[12:]}"
self._attr_unique_id = f"{blind.mac}-{motor}"
if self._motor not in ["Bottom", "Top", "Combined"]: if self._motor not in ["Bottom", "Top", "Combined"]:
_LOGGER.error("Unknown motor '%s'", self._motor) _LOGGER.error("Unknown motor '%s'", self._motor)
@property
def unique_id(self):
"""Return the unique id of the blind."""
return f"{self._blind.mac}-{self._motor}"
@property
def name(self):
"""Return the name of the blind."""
return f"{self._blind.blind_type}-{self._motor}-{self._blind.mac[12:]}"
@property @property
def current_cover_position(self): def current_cover_position(self):
""" """

View File

@ -46,26 +46,17 @@ class MotionBatterySensor(CoordinatorEntity, SensorEntity):
Updates are done by the cover platform. Updates are done by the cover platform.
""" """
_attr_device_class = DEVICE_CLASS_BATTERY
_attr_unit_of_measurement = PERCENTAGE
def __init__(self, coordinator, blind): def __init__(self, coordinator, blind):
"""Initialize the Motion Battery Sensor.""" """Initialize the Motion Battery Sensor."""
super().__init__(coordinator) super().__init__(coordinator)
self._blind = blind self._blind = blind
self._attr_device_info = {"identifiers": {(DOMAIN, blind.mac)}}
@property self._attr_name = f"{blind.blind_type}-battery-{blind.mac[12:]}"
def unique_id(self): self._attr_unique_id = f"{blind.mac}-battery"
"""Return the unique id of the blind."""
return f"{self._blind.mac}-battery"
@property
def device_info(self):
"""Return the device info of the blind."""
return {"identifiers": {(DOMAIN, self._blind.mac)}}
@property
def name(self):
"""Return the name of the blind battery sensor."""
return f"{self._blind.blind_type}-battery-{self._blind.mac[12:]}"
@property @property
def available(self): def available(self):
@ -78,16 +69,6 @@ class MotionBatterySensor(CoordinatorEntity, SensorEntity):
return self.coordinator.data[self._blind.mac][ATTR_AVAILABLE] return self.coordinator.data[self._blind.mac][ATTR_AVAILABLE]
@property
def unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any."""
return PERCENTAGE
@property
def device_class(self):
"""Return the device class of this entity."""
return DEVICE_CLASS_BATTERY
@property @property
def state(self): def state(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
@ -121,16 +102,8 @@ class MotionTDBUBatterySensor(MotionBatterySensor):
super().__init__(coordinator, blind) super().__init__(coordinator, blind)
self._motor = motor self._motor = motor
self._attr_unique_id = f"{blind.mac}-{motor}-battery"
@property self._attr_name = f"{blind.blind_type}-{motor}-battery-{blind.mac[12:]}"
def unique_id(self):
"""Return the unique id of the blind."""
return f"{self._blind.mac}-{self._motor}-battery"
@property
def name(self):
"""Return the name of the blind battery sensor."""
return f"{self._blind.blind_type}-{self._motor}-battery-{self._blind.mac[12:]}"
@property @property
def state(self): def state(self):
@ -153,22 +126,18 @@ class MotionTDBUBatterySensor(MotionBatterySensor):
class MotionSignalStrengthSensor(CoordinatorEntity, SensorEntity): class MotionSignalStrengthSensor(CoordinatorEntity, SensorEntity):
"""Representation of a Motion Signal Strength Sensor.""" """Representation of a Motion Signal Strength Sensor."""
_attr_device_class = DEVICE_CLASS_SIGNAL_STRENGTH
_attr_entity_registry_enabled_default = False
_attr_unit_of_measurement = SIGNAL_STRENGTH_DECIBELS_MILLIWATT
def __init__(self, coordinator, device, device_type): def __init__(self, coordinator, device, device_type):
"""Initialize the Motion Signal Strength Sensor.""" """Initialize the Motion Signal Strength Sensor."""
super().__init__(coordinator) super().__init__(coordinator)
self._device = device self._device = device
self._device_type = device_type self._device_type = device_type
self._attr_device_info = {"identifiers": {(DOMAIN, device.mac)}}
@property self._attr_unique_id = f"{device.mac}-RSSI"
def unique_id(self):
"""Return the unique id of the blind."""
return f"{self._device.mac}-RSSI"
@property
def device_info(self):
"""Return the device info of the blind."""
return {"identifiers": {(DOMAIN, self._device.mac)}}
@property @property
def name(self): def name(self):
@ -192,21 +161,6 @@ class MotionSignalStrengthSensor(CoordinatorEntity, SensorEntity):
and self.coordinator.data[self._device.mac][ATTR_AVAILABLE] and self.coordinator.data[self._device.mac][ATTR_AVAILABLE]
) )
@property
def unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any."""
return SIGNAL_STRENGTH_DECIBELS_MILLIWATT
@property
def device_class(self):
"""Return the device class of this entity."""
return DEVICE_CLASS_SIGNAL_STRENGTH
@property
def entity_registry_enabled_default(self):
"""Return if the entity should be enabled when first added to the entity registry."""
return False
@property @property
def state(self): def state(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""