mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 19:23:34 +00:00
Add rssi and signal_level to smartcam (#1392)
This commit is contained in:
parent
d890b0a3ac
commit
83eb73cc7f
@ -14,6 +14,13 @@ class DeviceModule(SmartCamModule):
|
|||||||
QUERY_MODULE_NAME = "device_info"
|
QUERY_MODULE_NAME = "device_info"
|
||||||
QUERY_SECTION_NAMES = ["basic_info", "info"]
|
QUERY_SECTION_NAMES = ["basic_info", "info"]
|
||||||
|
|
||||||
|
def query(self) -> dict:
|
||||||
|
"""Query to execute during the update cycle."""
|
||||||
|
q = super().query()
|
||||||
|
q["getConnectionType"] = {"network": {"get_connection_type": []}}
|
||||||
|
|
||||||
|
return q
|
||||||
|
|
||||||
def _initialize_features(self) -> None:
|
def _initialize_features(self) -> None:
|
||||||
"""Initialize features after the initial update."""
|
"""Initialize features after the initial update."""
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
@ -26,6 +33,32 @@ class DeviceModule(SmartCamModule):
|
|||||||
type=Feature.Type.Sensor,
|
type=Feature.Type.Sensor,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
if self.rssi is not None:
|
||||||
|
self._add_feature(
|
||||||
|
Feature(
|
||||||
|
self._device,
|
||||||
|
container=self,
|
||||||
|
id="rssi",
|
||||||
|
name="RSSI",
|
||||||
|
attribute_getter="rssi",
|
||||||
|
icon="mdi:signal",
|
||||||
|
unit_getter=lambda: "dBm",
|
||||||
|
category=Feature.Category.Debug,
|
||||||
|
type=Feature.Type.Sensor,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self._add_feature(
|
||||||
|
Feature(
|
||||||
|
self._device,
|
||||||
|
container=self,
|
||||||
|
id="signal_level",
|
||||||
|
name="Signal Level",
|
||||||
|
attribute_getter="signal_level",
|
||||||
|
icon="mdi:signal",
|
||||||
|
category=Feature.Category.Info,
|
||||||
|
type=Feature.Type.Sensor,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
async def _post_update_hook(self) -> None:
|
async def _post_update_hook(self) -> None:
|
||||||
"""Overriden to prevent module disabling.
|
"""Overriden to prevent module disabling.
|
||||||
@ -37,4 +70,14 @@ class DeviceModule(SmartCamModule):
|
|||||||
@property
|
@property
|
||||||
def device_id(self) -> str:
|
def device_id(self) -> str:
|
||||||
"""Return the device id."""
|
"""Return the device id."""
|
||||||
return self.data["basic_info"]["dev_id"]
|
return self.data[self.QUERY_GETTER_NAME]["basic_info"]["dev_id"]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def rssi(self) -> int | None:
|
||||||
|
"""Return the device id."""
|
||||||
|
return self.data["getConnectionType"].get("rssiValue")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def signal_level(self) -> int | None:
|
||||||
|
"""Return the device id."""
|
||||||
|
return self.data["getConnectionType"].get("rssi")
|
||||||
|
@ -185,6 +185,7 @@ class SmartCamDevice(SmartDevice):
|
|||||||
initial_query = {
|
initial_query = {
|
||||||
"getDeviceInfo": {"device_info": {"name": ["basic_info", "info"]}},
|
"getDeviceInfo": {"device_info": {"name": ["basic_info", "info"]}},
|
||||||
"getAppComponentList": {"app_component": {"name": "app_component_list"}},
|
"getAppComponentList": {"app_component": {"name": "app_component_list"}},
|
||||||
|
"getConnectionType": {"network": {"get_connection_type": {}}},
|
||||||
}
|
}
|
||||||
resp = await self.protocol.query(initial_query)
|
resp = await self.protocol.query(initial_query)
|
||||||
self._last_update.update(resp)
|
self._last_update.update(resp)
|
||||||
@ -261,3 +262,8 @@ class SmartCamDevice(SmartDevice):
|
|||||||
"dev_name": self.alias,
|
"dev_name": self.alias,
|
||||||
"oemId": self._info.get("oem_id"),
|
"oemId": self._info.get("oem_id"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@property
|
||||||
|
def rssi(self) -> int | None:
|
||||||
|
"""Return the device id."""
|
||||||
|
return self.modules[SmartCamModule.SmartCamDeviceModule].rssi
|
||||||
|
@ -33,6 +33,10 @@ class SmartCamModule(SmartModule):
|
|||||||
"BabyCryDetection"
|
"BabyCryDetection"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
SmartCamDeviceModule: Final[ModuleName[modules.DeviceModule]] = ModuleName(
|
||||||
|
"devicemodule"
|
||||||
|
)
|
||||||
|
|
||||||
#: Module name to be queried
|
#: Module name to be queried
|
||||||
QUERY_MODULE_NAME: str
|
QUERY_MODULE_NAME: str
|
||||||
#: Section name or names to be queried
|
#: Section name or names to be queried
|
||||||
|
Loading…
Reference in New Issue
Block a user