Small tweaks to LaCrosse (#51249)

This commit is contained in:
Franck Nijhof 2021-05-29 22:08:25 +02:00 committed by GitHub
parent ff6d05a200
commit d1f0ec8db8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 = {