mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Migrate websocket_api sensor to use shorthand attrs (#115620)
This commit is contained in:
parent
dbc5109fd8
commit
2ec588d2a6
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user