Skip to content

Commit f7d86de

Browse files
Foscam-wangzhengyufrenck
authored andcommitted
Fix the exception caused by the missing Foscam integration key (home-assistant#156022)
1 parent 6b49c8a commit f7d86de

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

homeassistant/components/foscam/coordinator.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class FoscamDeviceInfo:
3737
supports_speak_volume_adjustment: bool
3838
supports_pet_adjustment: bool
3939
supports_car_adjustment: bool
40+
supports_human_adjustment: bool
4041
supports_wdr_adjustment: bool
4142
supports_hdr_adjustment: bool
4243

@@ -144,24 +145,32 @@ def gather_all_configs(self) -> FoscamDeviceInfo:
144145
if ret_sw == 0
145146
else False
146147
)
147-
ret_md, mothion_config_val = self.session.get_motion_detect_config()
148+
human_adjustment_val = (
149+
bool(int(software_capabilities.get("swCapabilities2")) & 128)
150+
if ret_sw == 0
151+
else False
152+
)
153+
ret_md, motion_config_val = self.session.get_motion_detect_config()
148154
if pet_adjustment_val:
149155
is_pet_detection_on_val = (
150-
mothion_config_val["petEnable"] == "1" if ret_md == 0 else False
156+
motion_config_val.get("petEnable") == "1" if ret_md == 0 else False
151157
)
152158
else:
153159
is_pet_detection_on_val = False
154160

155161
if car_adjustment_val:
156162
is_car_detection_on_val = (
157-
mothion_config_val["carEnable"] == "1" if ret_md == 0 else False
163+
motion_config_val.get("carEnable") == "1" if ret_md == 0 else False
158164
)
159165
else:
160166
is_car_detection_on_val = False
161167

162-
is_human_detection_on_val = (
163-
mothion_config_val["humanEnable"] == "1" if ret_md == 0 else False
164-
)
168+
if human_adjustment_val:
169+
is_human_detection_on_val = (
170+
motion_config_val.get("humanEnable") == "1" if ret_md == 0 else False
171+
)
172+
else:
173+
is_human_detection_on_val = False
165174

166175
return FoscamDeviceInfo(
167176
dev_info=dev_info,
@@ -179,6 +188,7 @@ def gather_all_configs(self) -> FoscamDeviceInfo:
179188
supports_speak_volume_adjustment=supports_speak_volume_adjustment_val,
180189
supports_pet_adjustment=pet_adjustment_val,
181190
supports_car_adjustment=car_adjustment_val,
191+
supports_human_adjustment=human_adjustment_val,
182192
supports_hdr_adjustment=supports_hdr_adjustment_val,
183193
supports_wdr_adjustment=supports_wdr_adjustment_val,
184194
is_open_wdr=is_open_wdr,

homeassistant/components/foscam/switch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class FoscamSwitchEntityDescription(SwitchEntityDescription):
143143
native_value_fn=lambda data: data.is_human_detection_on,
144144
turn_off_fn=lambda session: set_motion_detection(session, "humanEnable", False),
145145
turn_on_fn=lambda session: set_motion_detection(session, "humanEnable", True),
146+
exists_fn=lambda coordinator: coordinator.data.supports_human_adjustment,
146147
),
147148
]
148149

tests/components/foscam/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def configure_mock_on_init(host, port, user, passwd, verbose=False):
7979
0,
8080
{
8181
"swCapabilities1": "100",
82-
"swCapabilities2": "768",
82+
"swCapabilities2": "896",
8383
"swCapabilities3": "100",
8484
"swCapabilities4": "100",
8585
},

0 commit comments

Comments
 (0)