From d1f0ec8db89113e2e4d71ac88357bd8a1a0aa4cf Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 29 May 2021 22:08:25 +0200 Subject: [PATCH] Small tweaks to LaCrosse (#51249) --- homeassistant/components/lacrosse/sensor.py | 47 ++++++--------------- 1 file changed, 13 insertions(+), 34 deletions(-) diff --git a/homeassistant/components/lacrosse/sensor.py b/homeassistant/components/lacrosse/sensor.py index 32090797f11..7c5557757ef 100644 --- a/homeassistant/components/lacrosse/sensor.py +++ b/homeassistant/components/lacrosse/sensor.py @@ -68,7 +68,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the LaCrosse sensors.""" - usb_device = config.get(CONF_DEVICE) baud = int(config.get(CONF_BAUD)) expire_after = config.get(CONF_EXPIRE_AFTER) @@ -127,28 +126,22 @@ class LaCrosseSensor(SensorEntity): ENTITY_ID_FORMAT, device_id, hass=hass ) self._config = config - self._name = name self._value = None self._expire_after = expire_after self._expiration_trigger = None + self._attr_name = name lacrosse.register_callback( int(self._config["id"]), self._callback_lacrosse, None ) - @property - def name(self): - """Return the name of the sensor.""" - return self._name - @property def extra_state_attributes(self): """Return the state attributes.""" - attributes = { + return { "low_battery": self._low_battery, "new_battery": self._new_battery, } - return attributes def _callback_lacrosse(self, lacrosse_sensor, user_data): """Handle a function that is called from pylacrosse with new values.""" @@ -181,10 +174,7 @@ class LaCrosseSensor(SensorEntity): class LaCrosseTemperature(LaCrosseSensor): """Implementation of a Lacrosse temperature sensor.""" - @property - def unit_of_measurement(self): - """Return the unit of measurement.""" - return TEMP_CELSIUS + _attr_unit_of_measurement = TEMP_CELSIUS @property def state(self): @@ -195,21 +185,14 @@ class LaCrosseTemperature(LaCrosseSensor): class LaCrosseHumidity(LaCrosseSensor): """Implementation of a Lacrosse humidity sensor.""" - @property - def unit_of_measurement(self): - """Return the unit of measurement.""" - return PERCENTAGE + _attr_unit_of_measurement = PERCENTAGE + _attr_icon = "mdi:water-percent" @property def state(self): """Return the state of the sensor.""" return self._humidity - @property - def icon(self): - """Icon to use in the frontend.""" - return "mdi:water-percent" - class LaCrosseBattery(LaCrosseSensor): """Implementation of a Lacrosse battery sensor.""" @@ -218,23 +201,19 @@ class LaCrosseBattery(LaCrosseSensor): def state(self): """Return the state of the sensor.""" if self._low_battery is None: - state = None - elif self._low_battery is True: - state = "low" - else: - state = "ok" - return state + return None + if self._low_battery is True: + return "low" + return "ok" @property def icon(self): """Icon to use in the frontend.""" if self._low_battery is None: - icon = "mdi:battery-unknown" - elif self._low_battery is True: - icon = "mdi:battery-alert" - else: - icon = "mdi:battery" - return icon + return "mdi:battery-unknown" + if self._low_battery is True: + return "mdi:battery-alert" + return "mdi:battery" TYPE_CLASSES = {