Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new keys for wifi, lfr, and battery #835

Merged
merged 10 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions blinkpy/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(self, sync):
self._cached_video = None
self.camera_type = ""
self.product_type = None
self.sync_signal_strength = None

@property
def attributes(self):
Expand All @@ -64,6 +65,7 @@ def attributes(self):
"wifi_strength": self.wifi_strength,
"network_id": self.sync.network_id,
"sync_module": self.sync.name,
"sync_signal_strength": self.sync_signal_strength,
"last_record": self.last_record,
"type": self.product_type,
}
Expand Down Expand Up @@ -229,15 +231,19 @@ def extract_config_info(self, config):
self.name = config.get("name", "unknown")
self.camera_id = str(config.get("id", "unknown"))
self.network_id = str(config.get("network_id", "unknown"))
self.serial = config.get("serial", None)
self.serial = config.get("serial")
self.motion_enabled = config.get("enabled", "unknown")
self.battery_voltage = config.get("battery_voltage", None)
self.battery_state = config.get("battery_state", None) or config.get(
"battery", None
)
self.temperature = config.get("temperature", None)
self.wifi_strength = config.get("wifi_strength", None)
self.product_type = config.get("type", None)
self.battery_state = config.get("battery_state") or config.get("battery")
self.temperature = config.get("temperature")
if signals := config.get("signals"):
self.wifi_strength = signals.get("wifi")
self.battery_voltage = signals.get("battery")
self.sync_signal_strength = signals.get("lfr")
else:
self.wifi_strength = config.get("wifi_strength")
self.battery_voltage = config.get("battery_voltage")

self.product_type = config.get("type")

async def get_sensor_info(self):
"""Retrieve calibrated temperature from special endpoint."""
Expand Down
25 changes: 24 additions & 1 deletion tests/test_camera_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async def test_camera_update(self, mock_resp):
"battery_voltage": 90,
"battery_state": "ok",
"temperature": 68,
"wifi_strength": 4,
"signals": {"lfr": 5, "wifi": 4, "battery": 3},
"thumbnail": "/thumb",
}
self.camera.last_record = ["1"]
Expand Down Expand Up @@ -408,3 +408,26 @@ async def test_save_recent_clips_exception(self, mock_clip, mock_open, mock_resp
in "\t".join(dl_log.output)
)
assert mock_open.call_count == 1

async def test_missing_keys(self, mock_resp):
"""Tests missing signal keys."""
config = {
"name": "new",
"id": 1234,
"network_id": 5678,
"serial": "12345678",
"enabled": False,
"battery_state": "ok",
"temperature": 68,
"signals": {"junk": 1},
"thumbnail": "",
}
self.camera.sync.homescreen = {"devices": []}
mock_resp.side_effect = [
{"temp": 71},
mresp.MockResponse({"test": 200}, 200, raw_data="test"),
mresp.MockResponse({"foobar": 200}, 200, raw_data="foobar"),
]
await self.camera.update(config, expire_clips=False, force=True)
self.assertEqual(self.camera.wifi_strength, None)
self.assertEqual(self.camera.battery_voltage, None)
Loading