From d35ded65027530e479041a45c52f723714ac3783 Mon Sep 17 00:00:00 2001 From: SMKRV Date: Fri, 22 Nov 2024 16:46:40 +0300 Subject: [PATCH] Release v2.0.0 --- custom_components/ha_text_ai/sensor.py | 46 +++++++++++++------------ icon.png => icons/icon.png | Bin 2 files changed, 24 insertions(+), 22 deletions(-) rename icon.png => icons/icon.png (100%) diff --git a/custom_components/ha_text_ai/sensor.py b/custom_components/ha_text_ai/sensor.py index 36383b0..1495ed7 100644 --- a/custom_components/ha_text_ai/sensor.py +++ b/custom_components/ha_text_ai/sensor.py @@ -59,26 +59,29 @@ async def async_setup_entry( coordinator = hass.data[DOMAIN][entry.entry_id] async_add_entities([HATextAISensor(coordinator, entry)], True) -def __init__( - self, - coordinator: HATextAICoordinator, - config_entry: ConfigEntry, -) -> None: - """Initialize the sensor.""" - super().__init__(coordinator) - self._config_entry = config_entry - self._attr_unique_id = config_entry.entry_id - self._attr_suggested_display_precision = 0 - self._error_count = 0 - self._last_error = None - self._state = STATE_INITIALIZING - self._attr_device_info = { - "identifiers": {(DOMAIN, self._attr_unique_id)}, - "name": "HA Text AI", - "manufacturer": "Community", - "model": f"{coordinator.model} ({self._config_entry.data.get(CONF_API_PROVIDER, 'Unknown')} provider)", - "sw_version": coordinator.api_version, - } +class HATextAISensor(CoordinatorEntity, SensorEntity): + """HA text AI Sensor.""" + + def __init__( + self, + coordinator: HATextAICoordinator, + config_entry: ConfigEntry, + ) -> None: + """Initialize the sensor.""" + super().__init__(coordinator) + self._config_entry = config_entry + self._attr_unique_id = config_entry.entry_id + self._attr_suggested_display_precision = 0 + self._error_count = 0 + self._last_error = None + self._state = STATE_INITIALIZING + self._attr_device_info = { + "identifiers": {(DOMAIN, self._attr_unique_id)}, + "name": "HA Text AI", + "manufacturer": "Community", + "model": f"{coordinator.model} ({self._config_entry.data.get(CONF_API_PROVIDER, 'Unknown')} provider)", + "sw_version": coordinator.api_version, + } @property def name(self) -> str: @@ -100,8 +103,7 @@ def __init__( last_response = self.coordinator.last_response if last_response and 'timestamp' in last_response: return dt_util.as_local(last_response['timestamp']) - - return None + return self._state @property def extra_state_attributes(self) -> Dict[str, Any]: diff --git a/icon.png b/icons/icon.png similarity index 100% rename from icon.png rename to icons/icon.png