mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Small tweaks to LaCrosse (#51249)
This commit is contained in:
parent
ff6d05a200
commit
d1f0ec8db8
@ -68,7 +68,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the LaCrosse sensors."""
|
"""Set up the LaCrosse sensors."""
|
||||||
|
|
||||||
usb_device = config.get(CONF_DEVICE)
|
usb_device = config.get(CONF_DEVICE)
|
||||||
baud = int(config.get(CONF_BAUD))
|
baud = int(config.get(CONF_BAUD))
|
||||||
expire_after = config.get(CONF_EXPIRE_AFTER)
|
expire_after = config.get(CONF_EXPIRE_AFTER)
|
||||||
@ -127,28 +126,22 @@ class LaCrosseSensor(SensorEntity):
|
|||||||
ENTITY_ID_FORMAT, device_id, hass=hass
|
ENTITY_ID_FORMAT, device_id, hass=hass
|
||||||
)
|
)
|
||||||
self._config = config
|
self._config = config
|
||||||
self._name = name
|
|
||||||
self._value = None
|
self._value = None
|
||||||
self._expire_after = expire_after
|
self._expire_after = expire_after
|
||||||
self._expiration_trigger = None
|
self._expiration_trigger = None
|
||||||
|
self._attr_name = name
|
||||||
|
|
||||||
lacrosse.register_callback(
|
lacrosse.register_callback(
|
||||||
int(self._config["id"]), self._callback_lacrosse, None
|
int(self._config["id"]), self._callback_lacrosse, None
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the sensor."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
attributes = {
|
return {
|
||||||
"low_battery": self._low_battery,
|
"low_battery": self._low_battery,
|
||||||
"new_battery": self._new_battery,
|
"new_battery": self._new_battery,
|
||||||
}
|
}
|
||||||
return attributes
|
|
||||||
|
|
||||||
def _callback_lacrosse(self, lacrosse_sensor, user_data):
|
def _callback_lacrosse(self, lacrosse_sensor, user_data):
|
||||||
"""Handle a function that is called from pylacrosse with new values."""
|
"""Handle a function that is called from pylacrosse with new values."""
|
||||||
@ -181,10 +174,7 @@ class LaCrosseSensor(SensorEntity):
|
|||||||
class LaCrosseTemperature(LaCrosseSensor):
|
class LaCrosseTemperature(LaCrosseSensor):
|
||||||
"""Implementation of a Lacrosse temperature sensor."""
|
"""Implementation of a Lacrosse temperature sensor."""
|
||||||
|
|
||||||
@property
|
_attr_unit_of_measurement = TEMP_CELSIUS
|
||||||
def unit_of_measurement(self):
|
|
||||||
"""Return the unit of measurement."""
|
|
||||||
return TEMP_CELSIUS
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
@ -195,21 +185,14 @@ class LaCrosseTemperature(LaCrosseSensor):
|
|||||||
class LaCrosseHumidity(LaCrosseSensor):
|
class LaCrosseHumidity(LaCrosseSensor):
|
||||||
"""Implementation of a Lacrosse humidity sensor."""
|
"""Implementation of a Lacrosse humidity sensor."""
|
||||||
|
|
||||||
@property
|
_attr_unit_of_measurement = PERCENTAGE
|
||||||
def unit_of_measurement(self):
|
_attr_icon = "mdi:water-percent"
|
||||||
"""Return the unit of measurement."""
|
|
||||||
return PERCENTAGE
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self._humidity
|
return self._humidity
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self):
|
|
||||||
"""Icon to use in the frontend."""
|
|
||||||
return "mdi:water-percent"
|
|
||||||
|
|
||||||
|
|
||||||
class LaCrosseBattery(LaCrosseSensor):
|
class LaCrosseBattery(LaCrosseSensor):
|
||||||
"""Implementation of a Lacrosse battery sensor."""
|
"""Implementation of a Lacrosse battery sensor."""
|
||||||
@ -218,23 +201,19 @@ class LaCrosseBattery(LaCrosseSensor):
|
|||||||
def state(self):
|
def state(self):
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
if self._low_battery is None:
|
if self._low_battery is None:
|
||||||
state = None
|
return None
|
||||||
elif self._low_battery is True:
|
if self._low_battery is True:
|
||||||
state = "low"
|
return "low"
|
||||||
else:
|
return "ok"
|
||||||
state = "ok"
|
|
||||||
return state
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def icon(self):
|
def icon(self):
|
||||||
"""Icon to use in the frontend."""
|
"""Icon to use in the frontend."""
|
||||||
if self._low_battery is None:
|
if self._low_battery is None:
|
||||||
icon = "mdi:battery-unknown"
|
return "mdi:battery-unknown"
|
||||||
elif self._low_battery is True:
|
if self._low_battery is True:
|
||||||
icon = "mdi:battery-alert"
|
return "mdi:battery-alert"
|
||||||
else:
|
return "mdi:battery"
|
||||||
icon = "mdi:battery"
|
|
||||||
return icon
|
|
||||||
|
|
||||||
|
|
||||||
TYPE_CLASSES = {
|
TYPE_CLASSES = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user