Added base station as a switch
### Feature * Base station has now been removed from binary sensors and added as a switch
This commit is contained in:
@@ -30,7 +30,7 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|||||||
from .const import CONF_OWLET_EXPIRY, CONF_OWLET_REFRESH, DOMAIN, SUPPORTED_VERSIONS
|
from .const import CONF_OWLET_EXPIRY, CONF_OWLET_REFRESH, DOMAIN, SUPPORTED_VERSIONS
|
||||||
from .coordinator import OwletCoordinator
|
from .coordinator import OwletCoordinator
|
||||||
|
|
||||||
PLATFORMS: list[Platform] = [Platform.BINARY_SENSOR, Platform.SENSOR]
|
PLATFORMS: list[Platform] = [Platform.BINARY_SENSOR, Platform.SENSOR, Platform.SWITCH]
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|||||||
@@ -92,12 +92,6 @@ SENSORS: tuple[OwletBinarySensorEntityDescription, ...] = (
|
|||||||
device_class=BinarySensorDeviceClass.POWER,
|
device_class=BinarySensorDeviceClass.POWER,
|
||||||
available_during_charging=True,
|
available_during_charging=True,
|
||||||
),
|
),
|
||||||
OwletBinarySensorEntityDescription(
|
|
||||||
key="base_station_on",
|
|
||||||
translation_key="base_on",
|
|
||||||
device_class=BinarySensorDeviceClass.POWER,
|
|
||||||
available_during_charging=True,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -177,4 +171,8 @@ class OwletAwakeSensor(OwletBinarySensor):
|
|||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
"""Return true if the binary sensor is on."""
|
"""Return true if the binary sensor is on."""
|
||||||
return False if self.sock.properties[self.entity_description.key] in [8, 15] else True
|
return (
|
||||||
|
False
|
||||||
|
if self.sock.properties[self.entity_description.key] in [8, 15]
|
||||||
|
else True
|
||||||
|
)
|
||||||
|
|||||||
@@ -11,5 +11,5 @@
|
|||||||
"requirements": [
|
"requirements": [
|
||||||
"pyowletapi==2024.10.1"
|
"pyowletapi==2024.10.1"
|
||||||
],
|
],
|
||||||
"version": "2024.9.1"
|
"version": "2024.10.1"
|
||||||
}
|
}
|
||||||
@@ -74,9 +74,6 @@
|
|||||||
},
|
},
|
||||||
"awake": {
|
"awake": {
|
||||||
"name": "Awake"
|
"name": "Awake"
|
||||||
},
|
|
||||||
"base_on": {
|
|
||||||
"name": "Base station on"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sensor": {
|
"sensor": {
|
||||||
@@ -116,6 +113,11 @@
|
|||||||
"movementbucket": {
|
"movementbucket": {
|
||||||
"name": "Movement bucket"
|
"name": "Movement bucket"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"switch": {
|
||||||
|
"base_on": {
|
||||||
|
"name": "Base station on"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
"""Support for Owlet switches."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from datetime import timedelta
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
|
from .const import DOMAIN
|
||||||
|
from .coordinator import OwletCoordinator
|
||||||
|
from .entity import OwletBaseEntity
|
||||||
|
|
||||||
|
SCAN_INTERVAL = timedelta(seconds=5)
|
||||||
|
PARALLEL_UPDATES = 0
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
|
"""Set up Owlet switch based on a config entry."""
|
||||||
|
coordinators: OwletCoordinator = hass.data[DOMAIN][config_entry.entry_id].values()
|
||||||
|
|
||||||
|
switches = []
|
||||||
|
for coordinator in coordinators:
|
||||||
|
switches.append(OwletBaseSwitch(coordinator))
|
||||||
|
async_add_entities(switches)
|
||||||
|
|
||||||
|
|
||||||
|
class OwletBaseSwitch(OwletBaseEntity, SwitchEntity):
|
||||||
|
"""Defines a Owlet switch."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
_attr_translation_key = "base_on"
|
||||||
|
|
||||||
|
def __init__(self, coordinator: OwletCoordinator) -> None:
|
||||||
|
"""Initialize ecobee ventilator platform."""
|
||||||
|
super().__init__(coordinator)
|
||||||
|
self._attr_unique_id = f"{self.sock.serial}-base_station_on"
|
||||||
|
self._attr_is_on = False
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_on(self):
|
||||||
|
return self.sock.properties["base_station_on"]
|
||||||
|
|
||||||
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
|
"""Turn on the switch."""
|
||||||
|
await self.sock.control_base_station(True)
|
||||||
|
|
||||||
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||||
|
"""Turn off the switch."""
|
||||||
|
await self.sock.control_base_station(False)
|
||||||
@@ -74,9 +74,6 @@
|
|||||||
},
|
},
|
||||||
"awake": {
|
"awake": {
|
||||||
"name": "Awake"
|
"name": "Awake"
|
||||||
},
|
|
||||||
"base_on": {
|
|
||||||
"name": "Base station on"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sensor": {
|
"sensor": {
|
||||||
@@ -116,6 +113,11 @@
|
|||||||
"movementbucket": {
|
"movementbucket": {
|
||||||
"name": "Movement bucket"
|
"name": "Movement bucket"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"switch": {
|
||||||
|
"base_on": {
|
||||||
|
"name": "Base station on"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,9 +74,6 @@
|
|||||||
},
|
},
|
||||||
"awake": {
|
"awake": {
|
||||||
"name": "Réveillé"
|
"name": "Réveillé"
|
||||||
},
|
|
||||||
"base_on": {
|
|
||||||
"name": "Station de base allumée"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sensor": {
|
"sensor": {
|
||||||
@@ -116,6 +113,11 @@
|
|||||||
"movementbucket": {
|
"movementbucket": {
|
||||||
"name": "Seuil de mouvement"
|
"name": "Seuil de mouvement"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"switch": {
|
||||||
|
"base_on": {
|
||||||
|
"name": "Station de base allumée"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,9 +74,6 @@
|
|||||||
},
|
},
|
||||||
"awake": {
|
"awake": {
|
||||||
"name": "Awake"
|
"name": "Awake"
|
||||||
},
|
|
||||||
"base_on": {
|
|
||||||
"name": "Base station on"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sensor": {
|
"sensor": {
|
||||||
@@ -116,6 +113,11 @@
|
|||||||
"movementbucket": {
|
"movementbucket": {
|
||||||
"name": "Movement bucket"
|
"name": "Movement bucket"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"switch": {
|
||||||
|
"base_on": {
|
||||||
|
"name": "Base station on"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user