Skip to content

Commit

Permalink
Update configuration of device
Browse files Browse the repository at this point in the history
- Add link to configuration page of EcoRT2
- Try to update configuration to solve #182
  • Loading branch information
pcourbin committed Jan 4, 2025
1 parent 756cbfe commit cf01b8b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 47 deletions.
1 change: 1 addition & 0 deletions custom_components/ecodevices_rt2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ async def async_update_data():
manufacturer="GCE",
model="Ecodevices RT2",
name=entry.data[CONF_NAME],
configuration_url=f"http://{entry.data[CONF_HOST]}:{entry.data[CONF_PORT]}",
)

if CONF_DEVICES not in entry.data:
Expand Down
58 changes: 11 additions & 47 deletions custom_components/ecodevices_rt2/device_ecodevicesrt2.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import re

from homeassistant.const import CONF_DEVICE_CLASS
from homeassistant.const import CONF_ICON
from homeassistant.const import CONF_NAME
from homeassistant.const import CONF_UNIT_OF_MEASUREMENT
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from homeassistant.util import slugify
from pyecodevices_rt2 import EcoDevicesRT2

from .const import CONF_COMPONENT
Expand All @@ -31,68 +30,33 @@ def __init__(

self.ecort2 = ecort2

self._name = device_config.get(CONF_NAME)
self._device_name = self._name
self._attr_name: str = device_config[CONF_NAME]
if suffix_name:
self._name += f" {suffix_name}"
self._attr_name = f"{self._attr_name} {suffix_name}"

self._device_class = device_config.get(CONF_DEVICE_CLASS)
self._unit_of_measurement = device_config.get(CONF_UNIT_OF_MEASUREMENT)
self._icon = device_config.get(CONF_ICON)
self._ecort2_type = device_config.get(CONF_TYPE)
self._component = device_config.get(CONF_COMPONENT)
self._id = device_config.get(CONF_ID)

self._zone_id = device_config.get(CONF_ZONE_ID, "")
self._subpost_id = device_config.get(CONF_SUBPOST_ID, "")

self._supported_features = 0

@property
def name(self):
"""Return the display name."""
return self._name
self._configuration_url = f"http://{self.ecort2.host}:{self.ecort2.port}"

@property
def unique_id(self):
"""Return an unique id."""
return "_".join(
[
DOMAIN,
self.ecort2.host,
self._component,
re.sub("[^A-Za-z0-9_]+", "", self._name.replace(" ", "_")).lower(),
]
self._attr_unique_id = "_".join(
[DOMAIN, self.ecort2.host, self._component, slugify(self._attr_name)]
)

@property
def device_info(self):
"""Return device info."""
return {
"identifiers": {
(
DOMAIN,
re.sub(
"[^A-Za-z0-9_]+", "", self._device_name.replace(" ", "_")
).lower(),
)
},
"name": self._device_name,
self._attr_device_info = {
"identifiers": {(DOMAIN, slugify(device_config[CONF_NAME]))},
"name": device_config[CONF_NAME],
"manufacturer": "GCE",
"model": "Ecodevices RT2",
"via_device": (DOMAIN, self.ecort2.host),
"configuration_url": self._configuration_url,
}

@property
def icon(self):
"""Icon to use in the frontend, if any."""
return self._icon

@property
def device_class(self):
"""Return the device class."""
return self._device_class

@property
def unit_of_measurement(self):
"""Return the unit of measurement."""
return self._unit_of_measurement

0 comments on commit cf01b8b

Please sign in to comment.