From d125dc7dbfcf19245317b24963b41af8e4106e6b Mon Sep 17 00:00:00 2001 From: Jonathan Keljo Date: Mon, 1 Nov 2021 06:25:02 -0700 Subject: [PATCH] Use _attr_ shorthand in greeneye_monitor sensors (#58784) --- .../components/greeneye_monitor/sensor.py | 29 ++++--------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/homeassistant/components/greeneye_monitor/sensor.py b/homeassistant/components/greeneye_monitor/sensor.py index 067b3e220d8..2a4692674c9 100644 --- a/homeassistant/components/greeneye_monitor/sensor.py +++ b/homeassistant/components/greeneye_monitor/sensor.py @@ -117,20 +117,13 @@ class GEMSensor(Generic[T], SensorEntity): ) -> None: """Construct the entity.""" self._monitor_serial_number = monitor_serial_number - self._name = name + self._attr_name = name self._sensor: T | None = None self._sensor_type = sensor_type self._number = number - - @property - def unique_id(self) -> str: - """Return a unique ID for this sensor.""" - return f"{self._monitor_serial_number}-{self._sensor_type}-{self._number}" - - @property - def name(self) -> str: - """Return the name of the channel.""" - return self._name + self._attr_unique_id = ( + f"{self._monitor_serial_number}-{self._sensor_type}-{self._number}" + ) async def async_added_to_hass(self) -> None: """Wait for and connect to the sensor.""" @@ -223,9 +216,9 @@ class PulseCounter(GEMSensor[greeneye.monitor.PulseCounter]): ) -> None: """Construct the entity.""" super().__init__(monitor_serial_number, name, "pulse", number) - self._counted_quantity = counted_quantity self._counted_quantity_per_pulse = counted_quantity_per_pulse self._time_unit = time_unit + self._attr_native_unit_of_measurement = f"{counted_quantity}/{self._time_unit}" def _get_sensor( self, monitor: greeneye.monitor.Monitor @@ -260,11 +253,6 @@ class PulseCounter(GEMSensor[greeneye.monitor.PulseCounter]): f"Invalid value for time unit: {self._time_unit}. Expected one of {TIME_SECONDS}, {TIME_MINUTES}, or {TIME_HOURS}" ) - @property - def native_unit_of_measurement(self) -> str: - """Return the unit of measurement for this pulse counter.""" - return f"{self._counted_quantity}/{self._time_unit}" - @property def extra_state_attributes(self) -> dict[str, Any] | None: """Return total pulses in the data dictionary.""" @@ -284,7 +272,7 @@ class TemperatureSensor(GEMSensor[greeneye.monitor.TemperatureSensor]): ) -> None: """Construct the entity.""" super().__init__(monitor_serial_number, name, "temp", number) - self._unit = unit + self._attr_native_unit_of_measurement = unit def _get_sensor( self, monitor: greeneye.monitor.Monitor @@ -299,11 +287,6 @@ class TemperatureSensor(GEMSensor[greeneye.monitor.TemperatureSensor]): return cast(Optional[float], self._sensor.temperature) - @property - def native_unit_of_measurement(self) -> str: - """Return the unit of measurement for this sensor (user specified).""" - return self._unit - class VoltageSensor(GEMSensor[greeneye.monitor.Monitor]): """Entity showing voltage."""