From 2ec588d2a6e391089687bffce307d64c07e2aaa6 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 15 Apr 2024 13:40:31 -0500 Subject: [PATCH] Migrate websocket_api sensor to use shorthand attrs (#115620) --- .../components/websocket_api/sensor.py | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/homeassistant/components/websocket_api/sensor.py b/homeassistant/components/websocket_api/sensor.py index 7d668466bc2..4d874bca74e 100644 --- a/homeassistant/components/websocket_api/sensor.py +++ b/homeassistant/components/websocket_api/sensor.py @@ -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()