mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Use shorthand attributes in Point (#100214)
This commit is contained in:
parent
54c034185f
commit
75951dd67b
@ -264,9 +264,20 @@ class MinutPointEntity(Entity):
|
|||||||
self._client = point_client
|
self._client = point_client
|
||||||
self._id = device_id
|
self._id = device_id
|
||||||
self._name = self.device.name
|
self._name = self.device.name
|
||||||
self._device_class = device_class
|
self._attr_device_class = device_class
|
||||||
self._updated = utc_from_timestamp(0)
|
self._updated = utc_from_timestamp(0)
|
||||||
self._value = None
|
self._attr_unique_id = f"point.{device_id}-{device_class}"
|
||||||
|
device = self.device.device
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
|
connections={(dr.CONNECTION_NETWORK_MAC, device["device_mac"])},
|
||||||
|
identifiers={(DOMAIN, device["device_id"])},
|
||||||
|
manufacturer="Minut",
|
||||||
|
model=f"Point v{device['hardware_version']}",
|
||||||
|
name=device["description"],
|
||||||
|
sw_version=device["firmware"]["installed"],
|
||||||
|
via_device=(DOMAIN, device["home"]),
|
||||||
|
)
|
||||||
|
self._attr_name = f"{self._name} {device_class.capitalize()}"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""Return string representation of device."""
|
"""Return string representation of device."""
|
||||||
@ -298,11 +309,6 @@ class MinutPointEntity(Entity):
|
|||||||
"""Return the representation of the device."""
|
"""Return the representation of the device."""
|
||||||
return self._client.device(self.device_id)
|
return self._client.device(self.device_id)
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self):
|
|
||||||
"""Return the device class."""
|
|
||||||
return self._device_class
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_id(self):
|
def device_id(self):
|
||||||
"""Return the id of the device."""
|
"""Return the id of the device."""
|
||||||
@ -317,25 +323,6 @@ class MinutPointEntity(Entity):
|
|||||||
)
|
)
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self) -> DeviceInfo:
|
|
||||||
"""Return a device description for device registry."""
|
|
||||||
device = self.device.device
|
|
||||||
return DeviceInfo(
|
|
||||||
connections={(dr.CONNECTION_NETWORK_MAC, device["device_mac"])},
|
|
||||||
identifiers={(DOMAIN, device["device_id"])},
|
|
||||||
manufacturer="Minut",
|
|
||||||
model=f"Point v{device['hardware_version']}",
|
|
||||||
name=device["description"],
|
|
||||||
sw_version=device["firmware"]["installed"],
|
|
||||||
via_device=(DOMAIN, device["home"]),
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the display name of this device."""
|
|
||||||
return f"{self._name} {self.device_class.capitalize()}"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_updated(self):
|
def is_updated(self):
|
||||||
"""Return true if sensor have been updated."""
|
"""Return true if sensor have been updated."""
|
||||||
@ -344,15 +331,4 @@ class MinutPointEntity(Entity):
|
|||||||
@property
|
@property
|
||||||
def last_update(self):
|
def last_update(self):
|
||||||
"""Return the last_update time for the device."""
|
"""Return the last_update time for the device."""
|
||||||
last_update = parse_datetime(self.device.last_update)
|
return parse_datetime(self.device.last_update)
|
||||||
return last_update
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Return the unique id of the sensor."""
|
|
||||||
return f"point.{self._id}-{self.device_class}"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def value(self):
|
|
||||||
"""Return the sensor value."""
|
|
||||||
return self._value
|
|
||||||
|
@ -76,6 +76,9 @@ class MinutPointBinarySensor(MinutPointEntity, BinarySensorEntity):
|
|||||||
self._device_name = device_name
|
self._device_name = device_name
|
||||||
self._async_unsub_hook_dispatcher_connect = None
|
self._async_unsub_hook_dispatcher_connect = None
|
||||||
self._events = EVENTS[device_name]
|
self._events = EVENTS[device_name]
|
||||||
|
self._attr_unique_id = f"point.{device_id}-{device_name}"
|
||||||
|
self._attr_icon = DEVICES[self._device_name].get("icon")
|
||||||
|
self._attr_name = f"{self._name} {device_name.capitalize()}"
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Call when entity is added to HOme Assistant."""
|
"""Call when entity is added to HOme Assistant."""
|
||||||
@ -124,18 +127,3 @@ class MinutPointBinarySensor(MinutPointEntity, BinarySensorEntity):
|
|||||||
else:
|
else:
|
||||||
self._attr_is_on = _is_on
|
self._attr_is_on = _is_on
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the display name of this device."""
|
|
||||||
return f"{self._name} {self._device_name.capitalize()}"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self):
|
|
||||||
"""Return the icon to use in the frontend, if any."""
|
|
||||||
return DEVICES[self._device_name].get("icon")
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Return the unique id of the sensor."""
|
|
||||||
return f"point.{self._id}-{self._device_name}"
|
|
||||||
|
@ -98,13 +98,10 @@ class MinutPointSensor(MinutPointEntity, SensorEntity):
|
|||||||
"""Update the value of the sensor."""
|
"""Update the value of the sensor."""
|
||||||
_LOGGER.debug("Update sensor value for %s", self)
|
_LOGGER.debug("Update sensor value for %s", self)
|
||||||
if self.is_updated:
|
if self.is_updated:
|
||||||
self._value = await self.device.sensor(self.device_class)
|
self._attr_native_value = await self.device.sensor(self.device_class)
|
||||||
|
if self.native_value is not None:
|
||||||
|
self._attr_native_value = round(
|
||||||
|
self.native_value, self.entity_description.precision
|
||||||
|
)
|
||||||
self._updated = parse_datetime(self.device.last_update)
|
self._updated = parse_datetime(self.device.last_update)
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@property
|
|
||||||
def native_value(self):
|
|
||||||
"""Return the state of the sensor."""
|
|
||||||
if self.value is None:
|
|
||||||
return None
|
|
||||||
return round(self.value, self.entity_description.precision)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user