99
1010from .const import DOMAIN
1111from .coordinator import NukiWebCoordinator
12+ from .entity import NukiEntity
1213
1314_LOGGER = logging .getLogger (__name__ )
1415
@@ -38,37 +39,17 @@ async def async_setup_entry(
3839
3940 async_add_entities (entities )
4041
41- class NukiBatteryCriticalSensor (CoordinatorEntity , BinarySensorEntity ):
42+ class NukiBatteryCriticalSensor (NukiEntity , BinarySensorEntity ):
4243 """Representation of a Nuki Web battery critical sensor."""
4344
4445 def __init__ (self , coordinator : NukiWebCoordinator , smartlock_id : int ) -> None :
4546 """Initialize."""
46- super ().__init__ (coordinator )
47- self ._smartlock_id = smartlock_id
47+ super ().__init__ (coordinator , smartlock_id )
4848 self ._attr_has_entity_name = True
4949 self ._attr_translation_key = "battery_critical"
5050 self ._attr_unique_id = f"{ smartlock_id } _battery_critical"
5151 self ._attr_device_class = BinarySensorDeviceClass .BATTERY
5252
53- @property
54- def available (self ) -> bool :
55- """Return if entity is available."""
56- return super ().available and self ._smartlock_id in self .coordinator .data
57-
58- @property
59- def device_info (self ):
60- """Return device info."""
61- if not self .available :
62- return None
63- data = self .coordinator .data [self ._smartlock_id ]
64- return {
65- "identifiers" : {(DOMAIN , str (self ._smartlock_id ))},
66- "name" : data ["name" ],
67- "manufacturer" : "Nuki" ,
68- "model" : f"Smart Lock Type { data .get ('type' )} " ,
69- "sw_version" : str (data .get ("firmwareVersion" )),
70- }
71-
7253 @property
7354 def is_on (self ) -> bool | None :
7455 """Return true if battery is critical."""
@@ -77,37 +58,17 @@ def is_on(self) -> bool | None:
7758 data = self .coordinator .data [self ._smartlock_id ]
7859 return data ["state" ].get ("batteryCritical" )
7960
80- class NukiDoorSensor (CoordinatorEntity , BinarySensorEntity ):
61+ class NukiDoorSensor (NukiEntity , BinarySensorEntity ):
8162 """Representation of a Nuki Web door sensor."""
8263
8364 def __init__ (self , coordinator : NukiWebCoordinator , smartlock_id : int ) -> None :
8465 """Initialize."""
85- super ().__init__ (coordinator )
86- self ._smartlock_id = smartlock_id
66+ super ().__init__ (coordinator , smartlock_id )
8767 self ._attr_has_entity_name = True
8868 self ._attr_translation_key = "door"
8969 self ._attr_unique_id = f"{ smartlock_id } _door"
9070 self ._attr_device_class = BinarySensorDeviceClass .DOOR
9171
92- @property
93- def available (self ) -> bool :
94- """Return if entity is available."""
95- return super ().available and self ._smartlock_id in self .coordinator .data
96-
97- @property
98- def device_info (self ):
99- """Return device info."""
100- if not self .available :
101- return None
102- data = self .coordinator .data [self ._smartlock_id ]
103- return {
104- "identifiers" : {(DOMAIN , str (self ._smartlock_id ))},
105- "name" : data ["name" ],
106- "manufacturer" : "Nuki" ,
107- "model" : f"Smart Lock Type { data .get ('type' )} " ,
108- "sw_version" : str (data .get ("firmwareVersion" )),
109- }
110-
11172 @property
11273 def is_on (self ) -> bool | None :
11374 """Return true if door is open."""
@@ -121,36 +82,16 @@ def is_on(self) -> bool | None:
12182 return False
12283 return None
12384
124- class NukiRingToOpenSensor (CoordinatorEntity , BinarySensorEntity ):
85+ class NukiRingToOpenSensor (NukiEntity , BinarySensorEntity ):
12586 """Representation of a Nuki Web Ring to Open sensor."""
12687
12788 def __init__ (self , coordinator : NukiWebCoordinator , smartlock_id : int ) -> None :
12889 """Initialize."""
129- super ().__init__ (coordinator )
130- self ._smartlock_id = smartlock_id
90+ super ().__init__ (coordinator , smartlock_id )
13191 self ._attr_has_entity_name = True
13292 self ._attr_translation_key = "ring_to_open"
13393 self ._attr_unique_id = f"{ smartlock_id } _rto"
13494 # No specific device class, maybe RUNNING?
135-
136- @property
137- def available (self ) -> bool :
138- """Return if entity is available."""
139- return super ().available and self ._smartlock_id in self .coordinator .data
140-
141- @property
142- def device_info (self ):
143- """Return device info."""
144- if not self .available :
145- return None
146- data = self .coordinator .data [self ._smartlock_id ]
147- return {
148- "identifiers" : {(DOMAIN , str (self ._smartlock_id ))},
149- "name" : data ["name" ],
150- "manufacturer" : "Nuki" ,
151- "model" : f"Smart Lock Type { data .get ('type' )} " ,
152- "sw_version" : str (data .get ("firmwareVersion" )),
153- }
15495
15596 @property
15697 def is_on (self ) -> bool | None :
0 commit comments