mirror of
https://github.com/natekspencer/hacs-oasis_mini.git
synced 2025-11-08 05:03:52 -05:00
Merge pull request #50 from natekspencer/binary-sensors
Switch busy and wifi_connected sensors to binary sensors
This commit is contained in:
@@ -19,6 +19,7 @@ type OasisMiniConfigEntry = ConfigEntry[OasisMiniCoordinator]
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
PLATFORMS = [
|
PLATFORMS = [
|
||||||
|
Platform.BINARY_SENSOR,
|
||||||
Platform.BUTTON,
|
Platform.BUTTON,
|
||||||
Platform.IMAGE,
|
Platform.IMAGE,
|
||||||
Platform.LIGHT,
|
Platform.LIGHT,
|
||||||
|
|||||||
55
custom_components/oasis_mini/binary_sensor.py
Normal file
55
custom_components/oasis_mini/binary_sensor.py
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
"""Oasis Mini binary sensor entity."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from homeassistant.components.binary_sensor import (
|
||||||
|
BinarySensorDeviceClass,
|
||||||
|
BinarySensorEntity,
|
||||||
|
BinarySensorEntityDescription,
|
||||||
|
)
|
||||||
|
from homeassistant.const import EntityCategory
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
|
from . import OasisMiniConfigEntry
|
||||||
|
from .coordinator import OasisMiniCoordinator
|
||||||
|
from .entity import OasisMiniEntity
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entry: OasisMiniConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
|
"""Set up Oasis Mini sensors using config entry."""
|
||||||
|
coordinator: OasisMiniCoordinator = entry.runtime_data
|
||||||
|
async_add_entities(
|
||||||
|
OasisMiniBinarySensorEntity(coordinator, descriptor)
|
||||||
|
for descriptor in DESCRIPTORS
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
DESCRIPTORS = {
|
||||||
|
BinarySensorEntityDescription(
|
||||||
|
key="busy",
|
||||||
|
translation_key="busy",
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
),
|
||||||
|
BinarySensorEntityDescription(
|
||||||
|
key="wifi_connected",
|
||||||
|
translation_key="wifi_status",
|
||||||
|
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class OasisMiniBinarySensorEntity(OasisMiniEntity, BinarySensorEntity):
|
||||||
|
"""Oasis Mini binary sensor entity."""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_on(self) -> bool:
|
||||||
|
"""Return true if the binary sensor is on."""
|
||||||
|
return getattr(self.device, self.entity_description.key)
|
||||||
@@ -52,13 +52,7 @@ DESCRIPTORS = {
|
|||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
)
|
)
|
||||||
for key in (
|
for key in ("error", "led_color_id", "status")
|
||||||
"busy",
|
|
||||||
"error",
|
|
||||||
"led_color_id",
|
|
||||||
"status",
|
|
||||||
"wifi_connected",
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CLOUD_DESCRIPTORS = (
|
CLOUD_DESCRIPTORS = (
|
||||||
|
|||||||
Reference in New Issue
Block a user