Skip to content

Commit

Permalink
Fix HomematicIP smoke detector detection type (home-assistant#34347)
Browse files Browse the repository at this point in the history
  • Loading branch information
SukramJ authored Apr 17, 2020
1 parent 267d98b commit 1c6e92c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
12 changes: 8 additions & 4 deletions homeassistant/components/homematicip_cloud/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
ATTR_ACCELERATION_SENSOR_NEUTRAL_POSITION = "acceleration_sensor_neutral_position"
ATTR_ACCELERATION_SENSOR_SENSITIVITY = "acceleration_sensor_sensitivity"
ATTR_ACCELERATION_SENSOR_TRIGGER_ANGLE = "acceleration_sensor_trigger_angle"
ATTR_INTRUSION_ALARM = "intrusion_alarm"
ATTR_MOISTURE_DETECTED = "moisture_detected"
ATTR_MOTION_DETECTED = "motion_detected"
ATTR_POWER_MAINS_FAILURE = "power_mains_failure"
Expand Down Expand Up @@ -229,7 +230,8 @@ def is_on(self) -> bool:
"""Return true if smoke is detected."""
if self._device.smokeDetectorAlarmType:
return (
self._device.smokeDetectorAlarmType != SmokeDetectorAlarmType.IDLE_OFF
self._device.smokeDetectorAlarmType
== SmokeDetectorAlarmType.PRIMARY_ALARM
)
return False

Expand Down Expand Up @@ -421,9 +423,11 @@ def device_state_attributes(self) -> Dict[str, Any]:
state_attr = super().device_state_attributes

smoke_detector_at = getattr(self._device, "smokeDetectorAlarmType", None)
if smoke_detector_at and smoke_detector_at != SmokeDetectorAlarmType.IDLE_OFF:
state_attr[ATTR_SMOKE_DETECTOR_ALARM] = str(smoke_detector_at)

if smoke_detector_at:
if smoke_detector_at == SmokeDetectorAlarmType.PRIMARY_ALARM:
state_attr[ATTR_SMOKE_DETECTOR_ALARM] = str(smoke_detector_at)
if smoke_detector_at == SmokeDetectorAlarmType.INTRUSION_ALARM:
state_attr[ATTR_INTRUSION_ALARM] = str(smoke_detector_at)
return state_attr

@property
Expand Down
9 changes: 9 additions & 0 deletions tests/components/homematicip_cloud/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,12 @@ async def test_hmip_security_sensor_group(hass, default_mock_hap_factory):
assert ha_state.attributes[ATTR_GROUP_MEMBER_UNREACHABLE]
assert ha_state.attributes[ATTR_SABOTAGE]
assert ha_state.attributes[ATTR_WINDOW_STATE] == WindowState.OPEN

await async_manipulate_test_data(
hass,
hmip_device,
"smokeDetectorAlarmType",
SmokeDetectorAlarmType.INTRUSION_ALARM,
)
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_ON

0 comments on commit 1c6e92c

Please sign in to comment.