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:
RyanClark123
2024-10-09 20:51:05 +01:00
parent 82823be1c8
commit f63e0a6dfe
8 changed files with 85 additions and 21 deletions
+1 -1
View File
@@ -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__)
+5 -7
View File
@@ -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
)
+1 -1
View File
@@ -11,5 +11,5 @@
"requirements": [ "requirements": [
"pyowletapi==2024.10.1" "pyowletapi==2024.10.1"
], ],
"version": "2024.9.1" "version": "2024.10.1"
} }
+5 -3
View File
@@ -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"
}
} }
} }
} }
+58
View File
@@ -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)
+5 -3
View File
@@ -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"
}
} }
} }
} }
+5 -3
View File
@@ -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"
}
} }
} }
} }
+5 -3
View File
@@ -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"
}
} }
} }
} }