@@ -47,6 +47,8 @@ async def async_setup_entry(
47
47
)
48
48
if zone .zone .detector_type == DetectorType .WIRELESS_EXTERNAL_MAGNET_DETECTOR :
49
49
devices .append (HikWirelessExtMagnetDetector (coordinator , zone .zone , entry .entry_id ))
50
+ if zone .zone .detector_type == DetectorType .WIRED_MAGNETIC_CONTACT :
51
+ devices .append (HikMagneticContactDetector (coordinator , zone .zone , entry .entry_id ))
50
52
if zone .zone .temperature is not None :
51
53
devices .append (HikTemperature (coordinator , zone .zone , entry .entry_id ))
52
54
if zone .zone .detector_type == DetectorType .WIRELESS_TEMPERATURE_HUMIDITY_DETECTOR :
@@ -113,6 +115,46 @@ def is_on(self) -> bool | None:
113
115
return False
114
116
115
117
118
+ class HikMagneticContactDetector (CoordinatorEntity , HikDevice , BinarySensorEntity ):
119
+ """Representation of Hikvision external magnet detector."""
120
+ coordinator : HikAxProDataUpdateCoordinator
121
+
122
+ def __init__ (self , coordinator : HikAxProDataUpdateCoordinator , zone : Zone , entry_id : str ) -> None :
123
+ """Create the entity with a DataUpdateCoordinator."""
124
+ super ().__init__ (coordinator )
125
+ self .zone = zone
126
+ self ._ref_id = entry_id
127
+ self ._attr_unique_id = f"{ self .coordinator .device_name } -magnet-{ zone .id } "
128
+ self ._attr_icon = "mdi:magnet"
129
+ #self._attr_name = f"Magnet presence"
130
+ self ._device_class = BinarySensorDeviceClass .PRESENCE
131
+ self ._attr_has_entity_name = True
132
+ self .entity_id = f"{ SENSOR_DOMAIN } .{ coordinator .device_name } -magnet-{ zone .id } "
133
+
134
+ @property
135
+ def name (self ) -> str | None :
136
+ return "Magnet presence"
137
+
138
+ @callback
139
+ def _handle_coordinator_update (self ) -> None :
140
+ """Handle updated data from the coordinator."""
141
+ self .async_write_ha_state ()
142
+ if self .coordinator .zones and self .coordinator .zones [self .zone .id ]:
143
+ value = self .coordinator .zones [self .zone .id ].magnet_open_status
144
+ self ._attr_state = STATE_ON if value is True else STATE_OFF
145
+ else :
146
+ self ._attr_state = None
147
+
148
+ @property
149
+ def is_on (self ) -> bool | None :
150
+ """Return true if the binary sensor is on."""
151
+ if self .coordinator .zones and self .coordinator .zones [self .zone .id ]:
152
+ value = self .coordinator .zones [self .zone .id ].status
153
+ return value == Status .ONLINE
154
+ else :
155
+ return False
156
+
157
+
116
158
class HikTemperature (CoordinatorEntity , HikDevice , SensorEntity ):
117
159
"""Representation of Hikvision external magnet detector."""
118
160
coordinator : HikAxProDataUpdateCoordinator
0 commit comments