From 75951dd67be7c2e149348c6171a9af5b07d4de8a Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Tue, 12 Sep 2023 17:15:36 +0200 Subject: [PATCH] Use shorthand attributes in Point (#100214) --- homeassistant/components/point/__init__.py | 52 +++++-------------- .../components/point/binary_sensor.py | 18 ++----- homeassistant/components/point/sensor.py | 13 ++--- 3 files changed, 22 insertions(+), 61 deletions(-) diff --git a/homeassistant/components/point/__init__.py b/homeassistant/components/point/__init__.py index 2030483d9cd..130ea116cc1 100644 --- a/homeassistant/components/point/__init__.py +++ b/homeassistant/components/point/__init__.py @@ -264,9 +264,20 @@ class MinutPointEntity(Entity): self._client = point_client self._id = device_id self._name = self.device.name - self._device_class = device_class + self._attr_device_class = device_class 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): """Return string representation of device.""" @@ -298,11 +309,6 @@ class MinutPointEntity(Entity): """Return the representation of the device.""" return self._client.device(self.device_id) - @property - def device_class(self): - """Return the device class.""" - return self._device_class - @property def device_id(self): """Return the id of the device.""" @@ -317,25 +323,6 @@ class MinutPointEntity(Entity): ) 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 def is_updated(self): """Return true if sensor have been updated.""" @@ -344,15 +331,4 @@ class MinutPointEntity(Entity): @property def last_update(self): """Return the last_update time for the device.""" - last_update = 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 + return parse_datetime(self.device.last_update) diff --git a/homeassistant/components/point/binary_sensor.py b/homeassistant/components/point/binary_sensor.py index e8db51fd0fc..81101d2da79 100644 --- a/homeassistant/components/point/binary_sensor.py +++ b/homeassistant/components/point/binary_sensor.py @@ -76,6 +76,9 @@ class MinutPointBinarySensor(MinutPointEntity, BinarySensorEntity): self._device_name = device_name self._async_unsub_hook_dispatcher_connect = None 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: """Call when entity is added to HOme Assistant.""" @@ -124,18 +127,3 @@ class MinutPointBinarySensor(MinutPointEntity, BinarySensorEntity): else: self._attr_is_on = _is_on 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}" diff --git a/homeassistant/components/point/sensor.py b/homeassistant/components/point/sensor.py index 34571c801a6..462d8270f0a 100644 --- a/homeassistant/components/point/sensor.py +++ b/homeassistant/components/point/sensor.py @@ -98,13 +98,10 @@ class MinutPointSensor(MinutPointEntity, SensorEntity): """Update the value of the sensor.""" _LOGGER.debug("Update sensor value for %s", self) 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.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)