Migrate websocket_api sensor to use shorthand attrs (#115620)

This commit is contained in:
J. Nick Koston 2024-04-15 13:40:31 -05:00 committed by GitHub
parent dbc5109fd8
commit 2ec588d2a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -30,9 +30,12 @@ async def async_setup_platform(
class APICount(SensorEntity):
"""Entity to represent how many people are connected to the stream API."""
_attr_name = "Connected clients"
_attr_native_unit_of_measurement = "clients"
def __init__(self) -> None:
"""Initialize the API count."""
self.count = 0
self._attr_native_value = 0
async def async_added_to_hass(self) -> None:
"""Handle addition to hass."""
@ -47,22 +50,7 @@ class APICount(SensorEntity):
)
)
@property
def name(self) -> str:
"""Return name of entity."""
return "Connected clients"
@property
def native_value(self) -> int:
"""Return current API count."""
return self.count
@property
def native_unit_of_measurement(self) -> str:
"""Return the unit of measurement."""
return "clients"
@callback
def _update_count(self) -> None:
self.count = self.hass.data.get(DATA_CONNECTIONS, 0)
self._attr_native_value = self.hass.data.get(DATA_CONNECTIONS, 0)
self.async_write_ha_state()