Add alarm module for smartcamera hubs (#1258)

This commit is contained in:
Steven B.
2024-11-15 10:19:40 +00:00
committed by GitHub
parent 5fe75cada9
commit cf77128853
6 changed files with 372 additions and 43 deletions

View File

@@ -3,12 +3,14 @@
from __future__ import annotations
import logging
from typing import TYPE_CHECKING, Any, cast
from typing import TYPE_CHECKING, Any, Final, cast
from ..exceptions import DeviceError, KasaException, SmartErrorCode
from ..modulemapping import ModuleName
from ..smart.smartmodule import SmartModule
if TYPE_CHECKING:
from . import modules
from .smartcamera import SmartCamera
_LOGGER = logging.getLogger(__name__)
@@ -17,12 +19,14 @@ _LOGGER = logging.getLogger(__name__)
class SmartCameraModule(SmartModule):
"""Base class for SMARTCAMERA modules."""
SmartCameraAlarm: Final[ModuleName[modules.Alarm]] = ModuleName("SmartCameraAlarm")
#: Query to execute during the main update cycle
QUERY_GETTER_NAME: str
#: Module name to be queried
QUERY_MODULE_NAME: str
#: Section name or names to be queried
QUERY_SECTION_NAMES: str | list[str]
QUERY_SECTION_NAMES: str | list[str] | None = None
REGISTERED_MODULES = {}
@@ -33,11 +37,10 @@ class SmartCameraModule(SmartModule):
Default implementation uses the raw query getter w/o parameters.
"""
return {
self.QUERY_GETTER_NAME: {
self.QUERY_MODULE_NAME: {"name": self.QUERY_SECTION_NAMES}
}
}
section_names = (
{"name": self.QUERY_SECTION_NAMES} if self.QUERY_SECTION_NAMES else {}
)
return {self.QUERY_GETTER_NAME: {self.QUERY_MODULE_NAME: section_names}}
async def call(self, method: str, params: dict | None = None) -> dict:
"""Call a method.