Skip to content

Commit cbead9b

Browse files
committed
add entities for tempo and hchp
1 parent 1dcd50a commit cbead9b

File tree

8 files changed

+394
-372
lines changed

8 files changed

+394
-372
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## 5.1.0
4+
5+
- Add binary sensor in Tempo and HCHP modes to know if currently in HC or not
6+
- Add sensor in Tempo mode to know today and tomorrow colors
7+
- Teleinfo instant power is now in VA instead of W
8+
- Remove warning message for HCHP and Tempo total entity when equal to 0
9+
310
## 5.0.0
411

512
- Add Tempo support

custom_components/ecodevices/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""GCE Eco-Devices integration."""
2+
23
import asyncio
34
from datetime import timedelta
45
import logging
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
"""Support for the GCE Eco-Devices binary sensors."""
2+
3+
import logging
4+
5+
from pyecodevices import EcoDevices
6+
7+
from homeassistant.components.binary_sensor import BinarySensorEntity
8+
from homeassistant.config_entries import ConfigEntry
9+
from homeassistant.core import HomeAssistant
10+
from homeassistant.helpers.entity_platform import AddEntitiesCallback
11+
from homeassistant.helpers.update_coordinator import (
12+
CoordinatorEntity,
13+
DataUpdateCoordinator,
14+
)
15+
from homeassistant.util import slugify
16+
17+
from .const import (
18+
CONF_T1_ENABLED,
19+
CONF_T1_TYPE,
20+
CONF_T2_ENABLED,
21+
CONF_T2_TYPE,
22+
CONF_TI_TYPE_HCHP,
23+
CONF_TI_TYPE_TEMPO,
24+
CONTROLLER,
25+
COORDINATOR,
26+
DEFAULT_T1_NAME,
27+
DEFAULT_T2_NAME,
28+
DOMAIN,
29+
)
30+
from .entity import get_device_info
31+
32+
_LOGGER = logging.getLogger(__name__)
33+
34+
35+
async def async_setup_entry(
36+
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
37+
) -> None:
38+
"""Set up the GCE Eco-Devices platform."""
39+
data = hass.data[DOMAIN][entry.entry_id]
40+
controller = data[CONTROLLER]
41+
coordinator = data[COORDINATOR]
42+
config = entry.data
43+
options = entry.options
44+
45+
t1_enabled = options.get(CONF_T1_ENABLED, config.get(CONF_T1_ENABLED))
46+
t1_type = options.get(CONF_T1_TYPE, config.get(CONF_T1_TYPE))
47+
t2_enabled = options.get(CONF_T2_ENABLED, config.get(CONF_T2_ENABLED))
48+
t2_type = options.get(CONF_T2_TYPE, config.get(CONF_T2_TYPE))
49+
50+
entities: list[BinarySensorEntity] = []
51+
52+
for input_number in (1, 2):
53+
if t1_enabled and input_number == 1 or t2_enabled and input_number == 2:
54+
_LOGGER.debug("Add the teleinfo %s binary_sensor entities", input_number)
55+
if t1_type in (CONF_TI_TYPE_HCHP, CONF_TI_TYPE_TEMPO) or t2_type in (
56+
CONF_TI_TYPE_HCHP,
57+
CONF_TI_TYPE_TEMPO,
58+
):
59+
prefix_name = DEFAULT_T1_NAME if input_number == 1 else DEFAULT_T2_NAME
60+
entities.append(
61+
TeleinfoInputHeuresCreuses(
62+
controller,
63+
coordinator,
64+
input_number=input_number,
65+
input_name="PTEC",
66+
name=f"{prefix_name} Heures Creuses",
67+
)
68+
)
69+
70+
if entities:
71+
async_add_entities(entities)
72+
73+
74+
class TeleinfoInputHeuresCreuses(CoordinatorEntity, BinarySensorEntity):
75+
"""Representation of a Eco-Devices HC binary sensor."""
76+
77+
_attr_icon = "mdi:cash-clock"
78+
79+
def __init__(
80+
self,
81+
controller: EcoDevices,
82+
coordinator: DataUpdateCoordinator,
83+
input_number: int,
84+
input_name: str,
85+
name: str,
86+
) -> None:
87+
"""Initialize the binary sensor."""
88+
super().__init__(coordinator)
89+
self.controller = controller
90+
self._input_number = input_number
91+
self._input_name = input_name
92+
self._attr_name = name
93+
self._attr_unique_id = slugify(
94+
f"{DOMAIN}_{self.controller.mac_address}_binary_sensor_{self._input_number}_{self._input_name}"
95+
)
96+
self._attr_device_info = get_device_info(self.controller)
97+
98+
@property
99+
def is_on(self) -> bool | None:
100+
"""Return the state."""
101+
if type_heure := self.coordinator.data.get(
102+
f"T{self._input_number}_{self._input_name}"
103+
):
104+
if type_heure.startswith("HC"):
105+
return True
106+
return False
107+
return None

custom_components/ecodevices/config_flow.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Config flow to configure the GCE Eco-Devices integration."""
2+
23
from typing import Any
34

45
from pyecodevices import (
@@ -9,7 +10,13 @@
910
import voluptuous as vol
1011

1112
from homeassistant.components.sensor import DEVICE_CLASSES as SENSOR_DEVICE_CLASSES
12-
from homeassistant.config_entries import HANDLERS, ConfigEntry, ConfigFlow, OptionsFlow
13+
from homeassistant.config_entries import (
14+
HANDLERS,
15+
ConfigEntry,
16+
ConfigFlow,
17+
ConfigFlowResult,
18+
OptionsFlow,
19+
)
1320
from homeassistant.const import (
1421
CONF_HOST,
1522
CONF_PASSWORD,
@@ -18,7 +25,6 @@
1825
CONF_USERNAME,
1926
)
2027
from homeassistant.core import callback
21-
from homeassistant.data_entry_flow import FlowResult
2228
from homeassistant.helpers.aiohttp_client import async_get_clientsession
2329

2430
from .const import (
@@ -67,7 +73,7 @@ def __init__(self) -> None:
6773
"""Initialize class variables."""
6874
self.base_input: dict[str, Any] = {}
6975

70-
async def async_step_user(self, user_input=None) -> FlowResult:
76+
async def async_step_user(self, user_input=None) -> ConfigFlowResult:
7177
"""Handle a flow initialized by the user."""
7278
errors: dict[str, str] = {}
7379
if user_input is None:
@@ -94,7 +100,7 @@ async def async_step_user(self, user_input=None) -> FlowResult:
94100
self.base_input = user_input
95101
return await self.async_step_params()
96102

97-
async def async_step_params(self, user_input=None) -> FlowResult:
103+
async def async_step_params(self, user_input=None) -> ConfigFlowResult:
98104
"""Handle the param flow to customize the device accordly to enabled inputs."""
99105
if user_input is not None:
100106
user_input.update(self.base_input)
@@ -123,7 +129,7 @@ def __init__(self, config_entry: ConfigEntry) -> None:
123129
self.config_entry: ConfigEntry = config_entry
124130
self.base_input: dict[str, Any] = {}
125131

126-
async def async_step_init(self, user_input) -> FlowResult:
132+
async def async_step_init(self, user_input) -> ConfigFlowResult:
127133
"""Manage the options."""
128134
errors = {}
129135
if user_input is not None:
@@ -160,7 +166,7 @@ async def async_step_init(self, user_input) -> FlowResult:
160166
step_id="init", data_schema=vol.Schema(options_schema), errors=errors
161167
)
162168

163-
async def async_step_params(self, user_input=None) -> FlowResult:
169+
async def async_step_params(self, user_input=None) -> ConfigFlowResult:
164170
"""Handle the param flow to customize the device accordly to enabled inputs."""
165171
if user_input is not None:
166172
user_input.update(self.base_input)

custom_components/ecodevices/const.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"""Constant for the eco-devices integration."""
2+
23
DOMAIN = "ecodevices"
34

45
CONTROLLER = "controller"
56
COORDINATOR = "coordinator"
6-
PLATFORMS = ["sensor"]
7+
PLATFORMS = ["binary_sensor", "sensor"]
78
UNDO_UPDATE_LISTENER = "undo_update_listener"
89

910
CONF_T1_ENABLED = "t1_enabled"
@@ -76,6 +77,6 @@
7677
"Jour Bleu HP": "BBRHPJB",
7778
"Jour Blanc HC": "BBRHCJW",
7879
"Jour Blanc HP": "BBRHPJW",
79-
"Jour Rouge HC": "BBRHCJR",
80-
"Jour Rouge HP": "BBRHPJR",
80+
"Jour Ro" + "uge HC": "BBRHCJR", # bypass codespell
81+
"Jour Ro" + "uge HP": "BBRHPJR", # bypass codespell
8182
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""Generic entity for EcoDevices."""
2+
3+
from pyecodevices import EcoDevices
4+
5+
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo
6+
7+
from .const import DOMAIN
8+
9+
10+
def get_device_info(controller: EcoDevices) -> DeviceInfo:
11+
"""Get device info."""
12+
return DeviceInfo(
13+
identifiers={(DOMAIN, controller.mac_address)},
14+
manufacturer="GCE Electronics",
15+
model="Eco-Devices",
16+
name=f"Eco-Devices {controller.host}:{controller.port!s}",
17+
sw_version=controller.version,
18+
connections={(CONNECTION_NETWORK_MAC, controller.mac_address)},
19+
configuration_url=f"http://{controller.host}:{controller.port}",
20+
)

custom_components/ecodevices/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
"xmltodict==0.13.0",
1414
"pyecodevices==1.6.1"
1515
],
16-
"version": "4.7.0"
16+
"version": "5.1.0"
1717
}

0 commit comments

Comments
 (0)