mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-09 20:24:02 +00:00
Add support for contact sensor (T110) (#877)
Initial support for T110 contact sensor & T110 fixture by courtesy of @ngaertner.
This commit is contained in:
@@ -8,6 +8,7 @@ from .childdevicemodule import ChildDeviceModule
|
||||
from .cloudmodule import CloudModule
|
||||
from .colormodule import ColorModule
|
||||
from .colortemp import ColorTemperatureModule
|
||||
from .contact import ContactSensor
|
||||
from .devicemodule import DeviceModule
|
||||
from .energymodule import EnergyModule
|
||||
from .fanmodule import FanModule
|
||||
@@ -45,5 +46,6 @@ __all__ = [
|
||||
"ColorTemperatureModule",
|
||||
"ColorModule",
|
||||
"WaterleakSensor",
|
||||
"ContactSensor",
|
||||
"FrostProtectionModule",
|
||||
]
|
||||
|
42
kasa/smart/modules/contact.py
Normal file
42
kasa/smart/modules/contact.py
Normal file
@@ -0,0 +1,42 @@
|
||||
"""Implementation of contact sensor module."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from ...feature import Feature
|
||||
from ..smartmodule import SmartModule
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..smartdevice import SmartDevice
|
||||
|
||||
|
||||
class ContactSensor(SmartModule):
|
||||
"""Implementation of contact sensor module."""
|
||||
|
||||
REQUIRED_COMPONENT = None # we depend on availability of key
|
||||
REQUIRED_KEY_ON_PARENT = "open"
|
||||
|
||||
def __init__(self, device: SmartDevice, module: str):
|
||||
super().__init__(device, module)
|
||||
self._add_feature(
|
||||
Feature(
|
||||
device,
|
||||
id="is_open",
|
||||
name="Open",
|
||||
container=self,
|
||||
attribute_getter="is_open",
|
||||
icon="mdi:door",
|
||||
category=Feature.Category.Primary,
|
||||
type=Feature.Type.BinarySensor,
|
||||
)
|
||||
)
|
||||
|
||||
def query(self) -> dict:
|
||||
"""Query to execute during the update cycle."""
|
||||
return {}
|
||||
|
||||
@property
|
||||
def is_open(self):
|
||||
"""Return True if the contact sensor is open."""
|
||||
return self._device.sys_info["open"]
|
Reference in New Issue
Block a user