diff --git a/custom_components/sws12500/sensor.py b/custom_components/sws12500/sensor.py index 4ebb0ea..00a2202 100644 --- a/custom_components/sws12500/sensor.py +++ b/custom_components/sws12500/sensor.py @@ -1,6 +1,5 @@ """Sensors definition for SWS12500.""" from dataclasses import dataclass -from typing import Any from homeassistant.components.sensor import ( SensorDeviceClass, @@ -20,13 +19,14 @@ from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.device_registry import DeviceEntryType from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.helpers.typing import StateType from homeassistant.helpers.update_coordinator import CoordinatorEntity from . import WeatherDataUpdateCoordinator from .const import ( BARO_PRESSURE, + CH2_HUMIDITY, + CH2_TEMP, DAILY_RAIN, DEW_POINT, DOMAIN, @@ -51,112 +51,112 @@ class WeatherSensorEntityDescription(SensorEntityDescription): SENSOR_TYPES: tuple[WeatherSensorEntityDescription, ...] = ( WeatherSensorEntityDescription( key=INDOOR_TEMP, - name="Indoor temperature", native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT, state_class=SensorStateClass.MEASUREMENT, icon="mdi:thermometer", device_class=SensorDeviceClass.TEMPERATURE, + translation_key=f"{INDOOR_TEMP}", ), WeatherSensorEntityDescription( key=INDOOR_HUMIDITY, - name="Indoor humidity", native_unit_of_measurement="%", state_class=SensorStateClass.MEASUREMENT, icon="mdi:thermometer", device_class=SensorDeviceClass.HUMIDITY, + translation_key=INDOOR_HUMIDITY, ), WeatherSensorEntityDescription( key=OUTSIDE_TEMP, - name="Outside Temperature", native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT, state_class=SensorStateClass.MEASUREMENT, icon="mdi:thermometer", device_class=SensorDeviceClass.TEMPERATURE, + translation_key=OUTSIDE_TEMP, ), WeatherSensorEntityDescription( key=OUTSIDE_HUMIDITY, - name="Outside humidity", native_unit_of_measurement="%", state_class=SensorStateClass.MEASUREMENT, icon="mdi:thermometer", device_class=SensorDeviceClass.HUMIDITY, + translation_key=OUTSIDE_HUMIDITY, ), WeatherSensorEntityDescription( key=DEW_POINT, - name="Dew point", native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT, state_class=SensorStateClass.MEASUREMENT, icon="mdi:thermometer-lines", device_class=SensorDeviceClass.TEMPERATURE, + translation_key=DEW_POINT, ), WeatherSensorEntityDescription( key=BARO_PRESSURE, - name="Barometric pressure", native_unit_of_measurement=UnitOfPressure.INHG, state_class=SensorStateClass.MEASUREMENT, icon="mdi:thermometer-lines", device_class=SensorDeviceClass.ATMOSPHERIC_PRESSURE, suggested_unit_of_measurement=UnitOfPressure.HPA, + translation_key=BARO_PRESSURE, ), WeatherSensorEntityDescription( key=WIND_SPEED, - name="Wind speed", native_unit_of_measurement=UnitOfSpeed.MILES_PER_HOUR, state_class=SensorStateClass.MEASUREMENT, device_class=SensorDeviceClass.WIND_SPEED, suggested_unit_of_measurement=UnitOfSpeed.KILOMETERS_PER_HOUR, icon="mdi:weather-windy", + translation_key=WIND_SPEED, ), WeatherSensorEntityDescription( key=WIND_GUST, - name="Wind gust", native_unit_of_measurement=UnitOfSpeed.MILES_PER_HOUR, state_class=SensorStateClass.MEASUREMENT, device_class=SensorDeviceClass.WIND_SPEED, suggested_unit_of_measurement=UnitOfSpeed.KILOMETERS_PER_HOUR, icon="mdi:windsock", + translation_key=WIND_GUST, ), WeatherSensorEntityDescription( key=WIND_DIR, - name="Wind direction", native_unit_of_measurement="°", state_class=SensorStateClass.MEASUREMENT, icon="mdi:sign-direction", + translation_key=WIND_DIR, ), WeatherSensorEntityDescription( key=RAIN, - name="Rain", native_unit_of_measurement=UnitOfPrecipitationDepth.INCHES, device_class=SensorDeviceClass.PRECIPITATION, state_class=SensorStateClass.TOTAL, suggested_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS, suggested_display_precision=2, icon="mdi:weather-pouring", + translation_key=RAIN, ), WeatherSensorEntityDescription( key=DAILY_RAIN, - name="Daily precipitation", native_unit_of_measurement="in/d", state_class=SensorStateClass.MEASUREMENT, device_class=SensorDeviceClass.PRECIPITATION_INTENSITY, suggested_unit_of_measurement="mm/h", suggested_display_precision=2, icon="mdi:weather-pouring", + translation_key=DAILY_RAIN, ), WeatherSensorEntityDescription( key=SOLAR_RADIATION, - name="Solar irradiance", native_unit_of_measurement=UnitOfIrradiance.WATTS_PER_SQUARE_METER, state_class=SensorStateClass.MEASUREMENT, device_class=SensorDeviceClass.IRRADIANCE, icon="mdi:weather-sunny", + translation_key=SOLAR_RADIATION, ), WeatherSensorEntityDescription( key=UV, - name="UV index", state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement="", icon="mdi:sunglasses", + translation_key=UV, ), ) @@ -195,8 +195,8 @@ class WeatherSensor(CoordinatorEntity[WeatherDataUpdateCoordinator], SensorEntit self.coordinator = coordinator self.entity_description = description self._state: StateType = None - self._attrs: dict[str, Any] = {} self._available = False + self._attr_unique_id = f"{DOMAIN}.{description.key}" @callback def _handle_coordinator_update(self) -> None: @@ -206,16 +206,6 @@ class WeatherSensor(CoordinatorEntity[WeatherDataUpdateCoordinator], SensorEntit self.async_write_ha_state() self.async_registry_entry_updated() - @property - def device_class(self) -> SensorDeviceClass: - """Return device class.""" - return self.entity_description.device_class - - @property - def name(self) -> str: - """Return the name of the switch.""" - return str(self.entity_description.name) - @property def unique_id(self) -> str: """Return a unique, Home Assistant friendly identifier for this entity.""" @@ -226,11 +216,6 @@ class WeatherSensor(CoordinatorEntity[WeatherDataUpdateCoordinator], SensorEntit """Return value of entity.""" return self._state - @property - def icon(self) -> str: - """Return icon of entity.""" - return str(self.entity_description.icon) - @property def native_unit_of_measurement(self) -> str: """Return unit of measurement.""" @@ -239,7 +224,6 @@ class WeatherSensor(CoordinatorEntity[WeatherDataUpdateCoordinator], SensorEntit @property def state_class(self) -> str: """Return stateClass.""" - return str(self.entity_description.state_class) @property diff --git a/custom_components/sws12500/strings.json b/custom_components/sws12500/strings.json index 0c539f4..3b0be99 100644 --- a/custom_components/sws12500/strings.json +++ b/custom_components/sws12500/strings.json @@ -58,5 +58,25 @@ "title": "Configure Windy" } } + }, + + "entity": { + "sensor": { + "indoor_temp": { "name": "Indoor temperature" }, + "indoor_humidity": { "name": "Indoor humidity" }, + "outside_temp": { "name": "Outside Temperature" }, + "outside_humidity": { "name": "Outside humidity" }, + "uv": { "name": "UV index" }, + "baro_pressure": { "name": "Barometric pressure" }, + "dew_point": { "name": "Dew point" }, + "wind_speed": { "name": "Wind speed" }, + "wind_dir": { "name": "Wind direction" }, + "wind_gust": { "name": "Wind gust" }, + "rain": { "name": "Rain" }, + "daily_rain": { "name": "Daily precipitation" }, + "solar_radiation": { "name": "Solar irradiance" }, + "ch2_temp": { "name": "Channel 2 temperature" }, + "ch2_humidity": { "name": "Channel 2 humidity" } + } } } diff --git a/custom_components/sws12500/translations/cs.json b/custom_components/sws12500/translations/cs.json new file mode 100644 index 0000000..10b4cf7 --- /dev/null +++ b/custom_components/sws12500/translations/cs.json @@ -0,0 +1,81 @@ +{ + "config": { + "error": { + "valid_credentials_api": "Vyplňte platné API ID.", + "valid_credentials_key": "Vyplňte platný API KEY.", + "valid_credentials_match": "API ID a API KEY nesmějí být stejné!" + }, + "step": { + "user": { + "data": { + "API_ID": "API ID / ID stanice", + "API_KEY": "API KEY / Heslo", + "dev_debug_checkbox": "Developer log" + }, + "description": "Zadejte API ID a API KEY, aby meteostanice mohla komunikovat s HomeAssistantem", + "title": "Nastavení přístpu pro metostanici", + "data_description": { + "dev_debug_checkbox": " Enable only if you want to send debuging data to the developer." + } + } + } + }, + "options": { + "error": { + "valid_credentials_api": "Vyplňte platné API ID", + "valid_credentials_key": "Vyplňte platný API KEY", + "valid_credentials_match": "API ID a API KEY nesmějí být stejné!", + "windy_key_required": "Je vyžadován Windy API key, pokud chcete aktivovat přeposílání dat na Windy" + }, + "step": { + "basic": { + "data": { + "API_ID": "API ID / ID Stanice", + "API_KEY": "API KEY / Heslo", + "dev_debug_checkbox": "Developer log" + }, + "description": "Zadejte API ID a API KEY, aby meteostanice mohla komunikovat s HomeAssistantem", + "title": "Nastavení přihlášení", + "data_description": { + "dev_debug_checkbox": " Enable only if you want to send debuging data to the developer." + } + }, + "init": { + "description": "Vyberte, co chcete konfigurovat. Zda přihlašovací údaje nebo nastavení pro přeposílání dat na Windy.", + "menu_options": { + "basic": "Základní - přístupové údaje (úřihlášení)", + "windy": "Nastavení pro přeposílání dat na Windy" + }, + "title": "Nastavení integrace SWS12500" + }, + "windy": { + "data": { + "WINDY_API_KEY": "Klíč API KEY získaný z Windy", + "windy_enabled_checkbox": "Povolit přeposílání dat na Windy", + "windy_logger_checkbox": "Logovat data a odpovědi z Windy" + }, + "description": "Přeposílání dat z metostanice na Windy", + "title": "Konfigurace Windy" + } + } + }, + "entity": { + "sensor": { + "indoor_temp": { "name": "Vnitřní teplota" }, + "indoor_humidity": { "name": "Vnitřní vlhkost vzduchu" }, + "outside_temp": { "name": "Venkovní teplota" }, + "outside_humidity": { "name": "Venkovní vlhkost vzduchu" }, + "uv": { "name": "UV index" }, + "baro_pressure": { "name": "Tlak vzduchu" }, + "dew_point": { "name": "Rosný bod" }, + "wind_speed": { "name": "Rychlost větrtu" }, + "wind_dir": { "name": "Směr větru" }, + "wind_gust": { "name": "Poryvy větru" }, + "rain": { "name": "Srážky" }, + "daily_rain": { "name": "Denní úhrn srážek" }, + "solar_radiation": { "name": "Sluneční osvit" }, + "ch2_temp": { "name": "Teplota senzoru 2" }, + "ch2_humidity": { "name": "Vlhkost sensoru 2" } + } + } +} diff --git a/custom_components/sws12500/translations/en.json b/custom_components/sws12500/translations/en.json index f307e82..3b0be99 100644 --- a/custom_components/sws12500/translations/en.json +++ b/custom_components/sws12500/translations/en.json @@ -10,7 +10,7 @@ "data": { "API_ID": "API ID / Station ID", "API_KEY": "API KEY / Password", - "dev_debug_checkbox": "Developer" + "dev_debug_checkbox": "Developer log" }, "description": "Provide API ID and API KEY so the Weather Station can access HomeAssistant", "title": "Configure access for Weather Station", @@ -32,12 +32,11 @@ "data": { "API_ID": "API ID / Station ID", "API_KEY": "API KEY / Password", - "dev_debug_checkbox": "Developer" + "dev_debug_checkbox": "Developer log" }, "description": "Provide API ID and API KEY so the Weather Station can access HomeAssistant", "title": "Configure credentials", "data_description": { - "api_id": "data desc.", "dev_debug_checkbox": " Enable only if you want to send debuging data to the developer." } }, @@ -59,5 +58,25 @@ "title": "Configure Windy" } } + }, + + "entity": { + "sensor": { + "indoor_temp": { "name": "Indoor temperature" }, + "indoor_humidity": { "name": "Indoor humidity" }, + "outside_temp": { "name": "Outside Temperature" }, + "outside_humidity": { "name": "Outside humidity" }, + "uv": { "name": "UV index" }, + "baro_pressure": { "name": "Barometric pressure" }, + "dew_point": { "name": "Dew point" }, + "wind_speed": { "name": "Wind speed" }, + "wind_dir": { "name": "Wind direction" }, + "wind_gust": { "name": "Wind gust" }, + "rain": { "name": "Rain" }, + "daily_rain": { "name": "Daily precipitation" }, + "solar_radiation": { "name": "Solar irradiance" }, + "ch2_temp": { "name": "Channel 2 temperature" }, + "ch2_humidity": { "name": "Channel 2 humidity" } + } } }