Use more shorthand attributes in threshold binary_sensor (#100343)

This commit is contained in:
J. Nick Koston 2023-09-14 02:03:39 -05:00 committed by GitHub
parent 58bb624b24
commit 182976f5d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -183,14 +183,14 @@ class ThresholdSensor(BinarySensorEntity):
self._attr_unique_id = unique_id
self._attr_device_info = device_info
self._entity_id = entity_id
self._name = name
self._attr_name = name
if lower is not None:
self._threshold_lower = lower
if upper is not None:
self._threshold_upper = upper
self.threshold_type = _threshold_type(lower, upper)
self._hysteresis: float = hysteresis
self._device_class = device_class
self._attr_device_class = device_class
self._state_position = POSITION_UNKNOWN
self._state: bool | None = None
self.sensor_value: float | None = None
@ -227,21 +227,11 @@ class ThresholdSensor(BinarySensorEntity):
)
_update_sensor_state()
@property
def name(self) -> str:
"""Return the name of the sensor."""
return self._name
@property
def is_on(self) -> bool | None:
"""Return true if sensor is on."""
return self._state
@property
def device_class(self) -> BinarySensorDeviceClass | None:
"""Return the sensor class of the sensor."""
return self._device_class
@property
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes of the sensor."""