forked from home-assistant/core
Focus on switch platform
This commit is contained in:
@@ -4,4 +4,4 @@ DOMAIN = "smarla"
|
|||||||
|
|
||||||
HOST = "https://devices.swing2sleep.de"
|
HOST = "https://devices.swing2sleep.de"
|
||||||
|
|
||||||
PLATFORMS = ["number", "sensor", "switch"]
|
PLATFORMS = ["switch"]
|
||||||
|
@@ -4,25 +4,6 @@
|
|||||||
"smartmode": {
|
"smartmode": {
|
||||||
"default": "mdi:refresh-auto"
|
"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"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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))
|
|
@@ -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]
|
|
||||||
)
|
|
@@ -19,25 +19,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"entity": {
|
"entity": {
|
||||||
"sensor": {
|
|
||||||
"amplitude": {
|
|
||||||
"name": "Amplitude"
|
|
||||||
},
|
|
||||||
"period": {
|
|
||||||
"name": "Period"
|
|
||||||
},
|
|
||||||
"activity": {
|
|
||||||
"name": "Activity"
|
|
||||||
},
|
|
||||||
"swing_count": {
|
|
||||||
"name": "Swing count"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"number": {
|
|
||||||
"intensity": {
|
|
||||||
"name": "Intensity"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"switch": {
|
"switch": {
|
||||||
"smartmode": {
|
"smartmode": {
|
||||||
"name": "Smart mode"
|
"name": "Smart mode"
|
||||||
|
Reference in New Issue
Block a user