From b6d51504c4dc4f58ebb27b2d80c2a3ba12411c9c Mon Sep 17 00:00:00 2001 From: Robin Lintermann Date: Thu, 17 Apr 2025 09:56:02 +0000 Subject: [PATCH] Focus on switch platform --- homeassistant/components/smarla/const.py | 2 +- homeassistant/components/smarla/icons.json | 19 --- homeassistant/components/smarla/number.py | 95 --------------- homeassistant/components/smarla/sensor.py | 122 ------------------- homeassistant/components/smarla/strings.json | 65 ++++------ 5 files changed, 24 insertions(+), 279 deletions(-) delete mode 100644 homeassistant/components/smarla/number.py delete mode 100644 homeassistant/components/smarla/sensor.py diff --git a/homeassistant/components/smarla/const.py b/homeassistant/components/smarla/const.py index 6890280291e..84acb908073 100644 --- a/homeassistant/components/smarla/const.py +++ b/homeassistant/components/smarla/const.py @@ -4,4 +4,4 @@ DOMAIN = "smarla" HOST = "https://devices.swing2sleep.de" -PLATFORMS = ["number", "sensor", "switch"] +PLATFORMS = ["switch"] diff --git a/homeassistant/components/smarla/icons.json b/homeassistant/components/smarla/icons.json index cabe61dbc71..20e7b4dcad1 100644 --- a/homeassistant/components/smarla/icons.json +++ b/homeassistant/components/smarla/icons.json @@ -4,25 +4,6 @@ "smartmode": { "default": "mdi:refresh-auto" } - }, - "number": { - "intensity": { - "default": "mdi:sine-wave" - } - }, - "sensor": { - "amplitude": { - "default": "mdi:sine-wave" - }, - "period": { - "default": "mdi:sine-wave" - }, - "activity": { - "default": "mdi:baby-face" - }, - "swing_count": { - "default": "mdi:counter" - } } } } diff --git a/homeassistant/components/smarla/number.py b/homeassistant/components/smarla/number.py deleted file mode 100644 index 8f8d2ec82c2..00000000000 --- a/homeassistant/components/smarla/number.py +++ /dev/null @@ -1,95 +0,0 @@ -"""Support for the Swing2Sleep Smarla number entities.""" - -from dataclasses import dataclass -from typing import Any - -from pysmarlaapi import Federwiege - -from homeassistant.components.number import ( - NumberEntity, - NumberEntityDescription, - NumberMode, -) -from homeassistant.core import HomeAssistant -from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback - -from . import FederwiegeConfigEntry -from .entity import SmarlaBaseEntity - - -@dataclass(frozen=True, kw_only=True) -class SmarlaNumberEntityDescription(NumberEntityDescription): - """Class describing Swing2Sleep Smarla number entities.""" - - service: str - property: str - - -NUMBER_TYPES: list[SmarlaNumberEntityDescription] = [ - SmarlaNumberEntityDescription( - key="intensity", - translation_key="intensity", - service="babywiege", - property="intensity", - native_max_value=100, - native_min_value=0, - native_step=1, - mode=NumberMode.SLIDER, - ), -] - - -async def async_setup_entry( - hass: HomeAssistant, - config_entry: FederwiegeConfigEntry, - async_add_entities: AddConfigEntryEntitiesCallback, -) -> None: - """Set up the Smarla numbers from config entry.""" - federwiege = config_entry.runtime_data - - entities: list[NumberEntity] = [] - - for desc in NUMBER_TYPES: - entity = SmarlaNumber(federwiege, desc) - entities.append(entity) - - async_add_entities(entities) - - -class SmarlaNumber(SmarlaBaseEntity, NumberEntity): - """Representation of Smarla number.""" - - async def on_change(self, value: Any): - """Notify ha when state changes.""" - self.async_write_ha_state() - - def __init__( - self, - federwiege: Federwiege, - description: SmarlaNumberEntityDescription, - ) -> None: - """Initialize a Smarla number.""" - super().__init__(federwiege) - self.property = federwiege.get_service(description.service).get_property( - description.property - ) - self.entity_description = description - self._attr_should_poll = False - self._attr_unique_id = f"{federwiege.serial_number}-{description.key}" - - async def async_added_to_hass(self) -> None: - """Run when this Entity has been added to HA.""" - await self.property.add_listener(self.on_change) - - async def async_will_remove_from_hass(self) -> None: - """Entity being removed from hass.""" - await self.property.remove_listener(self.on_change) - - @property - def native_value(self) -> float: - """Return the entity value to represent the entity state.""" - return self.property.get() - - def set_native_value(self, value: float) -> None: - """Update to the smarla device.""" - self.property.set(int(value)) diff --git a/homeassistant/components/smarla/sensor.py b/homeassistant/components/smarla/sensor.py deleted file mode 100644 index 1af4aa04a22..00000000000 --- a/homeassistant/components/smarla/sensor.py +++ /dev/null @@ -1,122 +0,0 @@ -"""Support for the Swing2Sleep Smarla sensor entities.""" - -from dataclasses import dataclass -from typing import Any - -from pysmarlaapi import Federwiege - -from homeassistant.components.sensor import ( - SensorEntity, - SensorEntityDescription, - SensorStateClass, -) -from homeassistant.const import UnitOfLength, UnitOfTime -from homeassistant.core import HomeAssistant -from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback - -from . import FederwiegeConfigEntry -from .entity import SmarlaBaseEntity - - -@dataclass(frozen=True, kw_only=True) -class SmarlaSensorEntityDescription(SensorEntityDescription): - """Class describing Swing2Sleep Smarla sensor entities.""" - - service: str - property: str - multiple: bool = False - value_pos: int = 0 - - -NUMBER_TYPES: list[SmarlaSensorEntityDescription] = [ - SmarlaSensorEntityDescription( - key="amplitude", - translation_key="amplitude", - service="analyser", - property="oscillation", - multiple=True, - value_pos=0, - native_unit_of_measurement=UnitOfLength.MILLIMETERS, - state_class=SensorStateClass.MEASUREMENT, - ), - SmarlaSensorEntityDescription( - key="period", - translation_key="period", - service="analyser", - property="oscillation", - multiple=True, - value_pos=1, - native_unit_of_measurement=UnitOfTime.MILLISECONDS, - state_class=SensorStateClass.MEASUREMENT, - ), - SmarlaSensorEntityDescription( - key="activity", - translation_key="activity", - service="analyser", - property="activity", - state_class=SensorStateClass.MEASUREMENT, - ), - SmarlaSensorEntityDescription( - key="swing_count", - translation_key="swing_count", - service="analyser", - property="swing_count", - state_class=SensorStateClass.MEASUREMENT, - ), -] - - -async def async_setup_entry( - hass: HomeAssistant, - config_entry: FederwiegeConfigEntry, - async_add_entities: AddConfigEntryEntitiesCallback, -) -> None: - """Set up the Smarla sensors from config entry.""" - federwiege = config_entry.runtime_data - - entities: list[SensorEntity] = [] - - for desc in NUMBER_TYPES: - entity = SmarlaSensor(federwiege, desc) - entities.append(entity) - - async_add_entities(entities) - - -class SmarlaSensor(SmarlaBaseEntity, SensorEntity): - """Representation of Smarla sensor.""" - - async def on_change(self, value: Any): - """Notify ha when state changes.""" - self.async_write_ha_state() - - def __init__( - self, - federwiege: Federwiege, - description: SmarlaSensorEntityDescription, - ) -> None: - """Initialize a Smarla sensor.""" - super().__init__(federwiege) - self.property = federwiege.get_service(description.service).get_property( - description.property - ) - self.entity_description = description - self.multiple = description.multiple - self.pos = description.value_pos - self._attr_should_poll = False - self._attr_unique_id = f"{federwiege.serial_number}-{description.key}" - - async def async_added_to_hass(self) -> None: - """Run when this Entity has been added to HA.""" - await self.property.add_listener(self.on_change) - - async def async_will_remove_from_hass(self) -> None: - """Entity being removed from hass.""" - await self.property.remove_listener(self.on_change) - - @property - def native_value(self) -> int: - """Return the entity value to represent the entity state.""" - return ( - self.property.get() if not self.multiple else self.property.get()[self.pos] - ) diff --git a/homeassistant/components/smarla/strings.json b/homeassistant/components/smarla/strings.json index 3300ac952d5..4d146b93814 100644 --- a/homeassistant/components/smarla/strings.json +++ b/homeassistant/components/smarla/strings.json @@ -1,47 +1,28 @@ { - "config": { - "error": { - "invalid_auth": "[%key:common::config_flow::error::invalid_auth%]", - "invalid_token": "Invalid access token" - }, - "step": { - "user": { - "data": { - "access_token": "[%key:common::config_flow::data::access_token%]" - }, - "data_description": { - "access_token": "The access token generated from the App." - } - } - }, - "abort": { - "already_configured": "[%key:common::config_flow::abort::already_configured_device%]" - } + "config": { + "error": { + "invalid_auth": "[%key:common::config_flow::error::invalid_auth%]", + "invalid_token": "Invalid access token" }, - "entity": { - "sensor": { - "amplitude": { - "name": "Amplitude" - }, - "period": { - "name": "Period" - }, - "activity": { - "name": "Activity" - }, - "swing_count": { - "name": "Swing count" - } + "step": { + "user": { + "data": { + "access_token": "[%key:common::config_flow::data::access_token%]" }, - "number": { - "intensity": { - "name": "Intensity" - } - }, - "switch": { - "smartmode": { - "name": "Smart mode" - } + "data_description": { + "access_token": "The access token generated from the App." } + } + }, + "abort": { + "already_configured": "[%key:common::config_flow::abort::already_configured_device%]" } -} \ No newline at end of file + }, + "entity": { + "switch": { + "smartmode": { + "name": "Smart mode" + } + } + } +}