1
0
mirror of https://github.com/natekspencer/hacs-oasis_mini.git synced 2025-12-06 18:44:14 -05:00

Dynamically handle devices and other enhancements

This commit is contained in:
Nathan Spencer
2025-11-23 22:49:26 +00:00
parent 83de1d5606
commit cf21a5d995
19 changed files with 430 additions and 170 deletions

View File

@@ -1,53 +1,57 @@
# """Oasis Mini switch entity."""
"""Oasis device switch entity."""
# from __future__ import annotations
from __future__ import annotations
# from typing import Any
from typing import Any
# from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
# from homeassistant.core import HomeAssistant
# from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
# from . import OasisMiniConfigEntry
# from .entity import OasisMiniEntity
from . import OasisDeviceConfigEntry, setup_platform_from_coordinator
from .entity import OasisDeviceEntity
from .pyoasiscontrol import OasisDevice
# async def async_setup_entry(
# hass: HomeAssistant,
# entry: OasisMiniConfigEntry,
# async_add_entities: AddEntitiesCallback,
# ) -> None:
# """Set up Oasis Mini switchs using config entry."""
# async_add_entities(
# [
# OasisMiniSwitchEntity(entry.runtime_data, descriptor)
# for descriptor in DESCRIPTORS
# ]
# )
async def async_setup_entry(
hass: HomeAssistant,
entry: OasisDeviceConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up Oasis device switchs using config entry."""
def make_entities(new_devices: list[OasisDevice]):
return [
OasisDeviceSwitchEntity(entry.runtime_data, device, descriptor)
for device in new_devices
for descriptor in DESCRIPTORS
]
setup_platform_from_coordinator(entry, async_add_entities, make_entities)
# class OasisMiniSwitchEntity(OasisMiniEntity, SwitchEntity):
# """Oasis Mini switch entity."""
# @property
# def is_on(self) -> bool:
# """Return True if entity is on."""
# return int(getattr(self.device, self.entity_description.key))
# async def async_turn_off(self, **kwargs: Any) -> None:
# """Turn the entity off."""
# await self.device.async_set_repeat_playlist(False)
# await self.coordinator.async_request_refresh()
# async def async_turn_on(self, **kwargs: Any) -> None:
# """Turn the entity on."""
# await self.device.async_set_repeat_playlist(True)
# await self.coordinator.async_request_refresh()
DESCRIPTORS = {
SwitchEntityDescription(
key="auto_clean",
translation_key="auto_clean",
entity_category=EntityCategory.CONFIG,
),
}
# DESCRIPTORS = {
# SwitchEntityDescription(
# key="repeat_playlist",
# name="Repeat playlist",
# ),
# }
class OasisDeviceSwitchEntity(OasisDeviceEntity, SwitchEntity):
"""Oasis device switch entity."""
@property
def is_on(self) -> bool:
"""Return True if entity is on."""
return bool(getattr(self.device, self.entity_description.key))
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the entity off."""
await self.device.async_set_auto_clean(False)
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the entity on."""
await self.device.async_set_auto_clean(True)