-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
394 additions
and
372 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
"""GCE Eco-Devices integration.""" | ||
|
||
import asyncio | ||
from datetime import timedelta | ||
import logging | ||
|
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,107 @@ | ||
"""Support for the GCE Eco-Devices binary sensors.""" | ||
|
||
import logging | ||
|
||
from pyecodevices import EcoDevices | ||
|
||
from homeassistant.components.binary_sensor import BinarySensorEntity | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
from homeassistant.helpers.update_coordinator import ( | ||
CoordinatorEntity, | ||
DataUpdateCoordinator, | ||
) | ||
from homeassistant.util import slugify | ||
|
||
from .const import ( | ||
CONF_T1_ENABLED, | ||
CONF_T1_TYPE, | ||
CONF_T2_ENABLED, | ||
CONF_T2_TYPE, | ||
CONF_TI_TYPE_HCHP, | ||
CONF_TI_TYPE_TEMPO, | ||
CONTROLLER, | ||
COORDINATOR, | ||
DEFAULT_T1_NAME, | ||
DEFAULT_T2_NAME, | ||
DOMAIN, | ||
) | ||
from .entity import get_device_info | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback | ||
) -> None: | ||
"""Set up the GCE Eco-Devices platform.""" | ||
data = hass.data[DOMAIN][entry.entry_id] | ||
controller = data[CONTROLLER] | ||
coordinator = data[COORDINATOR] | ||
config = entry.data | ||
options = entry.options | ||
|
||
t1_enabled = options.get(CONF_T1_ENABLED, config.get(CONF_T1_ENABLED)) | ||
t1_type = options.get(CONF_T1_TYPE, config.get(CONF_T1_TYPE)) | ||
t2_enabled = options.get(CONF_T2_ENABLED, config.get(CONF_T2_ENABLED)) | ||
t2_type = options.get(CONF_T2_TYPE, config.get(CONF_T2_TYPE)) | ||
|
||
entities: list[BinarySensorEntity] = [] | ||
|
||
for input_number in (1, 2): | ||
if t1_enabled and input_number == 1 or t2_enabled and input_number == 2: | ||
_LOGGER.debug("Add the teleinfo %s binary_sensor entities", input_number) | ||
if t1_type in (CONF_TI_TYPE_HCHP, CONF_TI_TYPE_TEMPO) or t2_type in ( | ||
CONF_TI_TYPE_HCHP, | ||
CONF_TI_TYPE_TEMPO, | ||
): | ||
prefix_name = DEFAULT_T1_NAME if input_number == 1 else DEFAULT_T2_NAME | ||
entities.append( | ||
TeleinfoInputHeuresCreuses( | ||
controller, | ||
coordinator, | ||
input_number=input_number, | ||
input_name="PTEC", | ||
name=f"{prefix_name} Heures Creuses", | ||
) | ||
) | ||
|
||
if entities: | ||
async_add_entities(entities) | ||
|
||
|
||
class TeleinfoInputHeuresCreuses(CoordinatorEntity, BinarySensorEntity): | ||
"""Representation of a Eco-Devices HC binary sensor.""" | ||
|
||
_attr_icon = "mdi:cash-clock" | ||
|
||
def __init__( | ||
self, | ||
controller: EcoDevices, | ||
coordinator: DataUpdateCoordinator, | ||
input_number: int, | ||
input_name: str, | ||
name: str, | ||
) -> None: | ||
"""Initialize the binary sensor.""" | ||
super().__init__(coordinator) | ||
self.controller = controller | ||
self._input_number = input_number | ||
self._input_name = input_name | ||
self._attr_name = name | ||
self._attr_unique_id = slugify( | ||
f"{DOMAIN}_{self.controller.mac_address}_binary_sensor_{self._input_number}_{self._input_name}" | ||
) | ||
self._attr_device_info = get_device_info(self.controller) | ||
|
||
@property | ||
def is_on(self) -> bool | None: | ||
"""Return the state.""" | ||
if type_heure := self.coordinator.data.get( | ||
f"T{self._input_number}_{self._input_name}" | ||
): | ||
if type_heure.startswith("HC"): | ||
return True | ||
return False | ||
return None |
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
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,20 @@ | ||
"""Generic entity for EcoDevices.""" | ||
|
||
from pyecodevices import EcoDevices | ||
|
||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo | ||
|
||
from .const import DOMAIN | ||
|
||
|
||
def get_device_info(controller: EcoDevices) -> DeviceInfo: | ||
"""Get device info.""" | ||
return DeviceInfo( | ||
identifiers={(DOMAIN, controller.mac_address)}, | ||
manufacturer="GCE Electronics", | ||
model="Eco-Devices", | ||
name=f"Eco-Devices {controller.host}:{controller.port!s}", | ||
sw_version=controller.version, | ||
connections={(CONNECTION_NETWORK_MAC, controller.mac_address)}, | ||
configuration_url=f"http://{controller.host}:{controller.port}", | ||
) |
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 |
---|---|---|
|
@@ -13,5 +13,5 @@ | |
"xmltodict==0.13.0", | ||
"pyecodevices==1.6.1" | ||
], | ||
"version": "4.7.0" | ||
"version": "5.1.0" | ||
} |
Oops, something went wrong.