forked from joleys/niko-home-control-II
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add entities related to CocoElectricalheatingAction
- Loading branch information
1 parent
7260d60
commit c8e383f
Showing
4 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
custom_components/nhc2/entities/electricalheating_action_basicstate.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from homeassistant.components.binary_sensor import BinarySensorEntity | ||
|
||
from ..const import DOMAIN, BRAND | ||
|
||
from ..nhccoco.devices.electricalheating_action import CocoElectricalheatingAction | ||
|
||
|
||
class Nhc2ElectricalheatingActionBasicStateEntity(BinarySensorEntity): | ||
_attr_has_entity_name = True | ||
|
||
def __init__(self, device_instance: CocoElectricalheatingAction, hub, gateway): | ||
"""Initialize a binary sensor.""" | ||
self._device = device_instance | ||
self._hub = hub | ||
self._gateway = gateway | ||
|
||
self._device.after_change_callbacks.append(self.on_change) | ||
|
||
self._attr_available = self._device.is_online | ||
self._attr_unique_id = device_instance.uuid + '_basic_state' | ||
self._attr_should_poll = False | ||
|
||
self._attr_state = self._device.is_basic_state_on | ||
self._attr_state_class = None | ||
|
||
@property | ||
def name(self) -> str: | ||
return 'Basic State' | ||
|
||
@property | ||
def device_info(self): | ||
"""Return the device info.""" | ||
return { | ||
'identifiers': { | ||
(DOMAIN, self._device.uuid) | ||
}, | ||
'name': self._device.name, | ||
'manufacturer': BRAND, | ||
'model': str.title(f'{self._device.model} ({self._device.type})'), | ||
'via_device': self._hub | ||
} | ||
|
||
@property | ||
def is_on(self) -> bool: | ||
return self._device.is_basic_state_on | ||
|
||
def on_change(self): | ||
self.schedule_update_ha_state() |
46 changes: 46 additions & 0 deletions
46
custom_components/nhc2/entities/electricalheating_action_button.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from homeassistant.components.button import ButtonEntity | ||
|
||
from ..const import DOMAIN, BRAND | ||
|
||
from ..nhccoco.devices.electricalheating_action import CocoElectricalheatingAction | ||
|
||
|
||
class Nhc2ElectricalHeatingActionButtonEntity(ButtonEntity): | ||
_attr_has_entity_name = True | ||
_attr_name = None | ||
|
||
def __init__(self, device_instance: CocoElectricalheatingAction, hub, gateway): | ||
"""Initialize a button.""" | ||
self._device = device_instance | ||
self._hub = hub | ||
self._gateway = gateway | ||
|
||
self._device.after_change_callbacks.append(self.on_change) | ||
|
||
self._attr_available = self._device.is_online | ||
self._attr_unique_id = device_instance.uuid | ||
self._attr_should_poll = False | ||
|
||
@property | ||
def device_info(self): | ||
"""Return the device info.""" | ||
return { | ||
'identifiers': { | ||
(DOMAIN, self._device.uuid) | ||
}, | ||
'name': self._device.name, | ||
'manufacturer': BRAND, | ||
'model': str.title(f'{self._device.model} ({self._device.type})'), | ||
'via_device': self._hub | ||
} | ||
|
||
@property | ||
def is_on(self) -> bool: | ||
return self._device.is_basic_state_on | ||
|
||
def on_change(self): | ||
self.schedule_update_ha_state() | ||
|
||
async def async_press(self) -> None: | ||
self._device.press(self._gateway) | ||
self.on_change() |