Skip to content

Commit

Permalink
πŸ”– v1.0.7-beta-3
Browse files Browse the repository at this point in the history
⚰️ deprecated configuration 

🌱 add custom device_class 

⚰️ remove List import 

🌱 clean up 

πŸ“ deprecated 

πŸ”– v1.0.7-beta-3 

πŸ“ deprecated 

🌱 add Exception
  • Loading branch information
Ludy87 authored May 19, 2022
2 parents cb5e4fd + 26071bc commit 2a9b83f
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 56 deletions.
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ ecotrend_ista:
### optional
```yaml
unit: "kwh"
unit_heating: "kwh"
unit_warmwater: "kwh"
unit_heating: "Einheiten" # default kwh
unit_warmwater: "mΒ³" # default kwh
```
```yaml
Expand All @@ -54,7 +53,12 @@ yearmonth:
```yaml
scan_interval: 39600
```
---
### deprecated v1.0.7-beta-3
```yaml
unit: "kwh"
```
---
## Template
Expand All @@ -65,15 +69,35 @@ scan_interval: 39600
- name: ECO Heizung Einheiten
unit_of_measurement: "Einheiten"
state: "{{ state_attr('sensor.heating_XXXXXXXXX', 'value') }}"
state_class: total
- name: ECO Heizung kwh
unit_of_measurement: "kwh"
state: "{{ state_attr('sensor.heating_XXXXXXXXX', 'valuekwh') }}"
state_class: total
- name: ECO Wasserverbrauch mΒ³
unit_of_measurement: "mΒ³"
state: "{{ state_attr('sensor.warmwater_XXXXXXXXX', 'value') }}"
state_class: total
- name: ECO Wasserverbrauch kwh
unit_of_measurement: "kwh"
state: "{{ state_attr('sensor.warmwater_XXXXXXXXX', 'valuekwh') }}"
state_class: total
- name: ECO Heizung Einheiten 03/2022
unit_of_measurement: "Einheiten"
state: "{{ state_attr('sensor.heating_2022_3_XXXXXXXXX', 'value') }}"
state_class: total
- name: ECO Heizung kwh 03/2022
unit_of_measurement: "kwh"
state: "{{ state_attr('sensor.heating_2022_3_XXXXXXXXX', 'valuekwh') }}"
state_class: total
- name: ECO Wasserverbrauch mΒ³ 03/2022
unit_of_measurement: "mΒ³"
state: "{{ state_attr('sensor.warmwater_2022_3_XXXXXXXXX', 'value') }}"
state_class: total
- name: ECO Wasserverbrauch kwh 03/2022
unit_of_measurement: "kwh"
state: "{{ state_attr('sensor.warmwater_2022_3_XXXXXXXXX', 'valuekwh') }}"
state_class: total
```
![](./image/template.png)
Expand Down
31 changes: 18 additions & 13 deletions custom_components/ecotrend_ista/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
CONF_YEARMONTH,
DEFAULT_SCAN_INTERVAL_TIME,
DOMAIN,
UNIT_SUPPORT,
UNIT_SUPPORT_HEATING,
UNIT_SUPPORT_WARMWATER,
)

from pyecotrend_ista import pyecotrend_ista as ista
Expand All @@ -39,9 +40,14 @@
{
vol.Required(CONF_EMAIL): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Optional(CONF_UNIT, default=""): cv.string,
vol.Optional(CONF_UNIT_HEATING, default=""): cv.string,
vol.Optional(CONF_UNIT_WARMWATER, default=""): cv.string,
##############################################
########## deprecated configuration ##########
##############################################
########## options v1.0.7-beta-3 #############
vol.Remove(CONF_UNIT): cv.string, ###########
##############################################
vol.Optional(CONF_UNIT_HEATING, default="kwh"): cv.string,
vol.Optional(CONF_UNIT_WARMWATER, default="kwh"): cv.string,
vol.Optional(CONF_YEAR, default=[]): cv.ensure_list,
vol.Optional(CONF_YEARMONTH, default=[]): cv.ensure_list,
vol.Optional(CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL): cv.time_period,
Expand All @@ -57,7 +63,6 @@
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
hass.data[CONF_EMAIL] = []
hass.data[CONF_PASSWORD] = []
hass.data[CONF_UNIT] = []
hass.data[CONF_UNIT_HEATING] = []
hass.data[CONF_UNIT_WARMWATER] = []
hass.data[CONF_UPDATE_FREQUENCY] = []
Expand All @@ -73,21 +78,21 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
async def _setup_controller(hass: HomeAssistant, controller_config, config: ConfigType) -> bool:
email: str = controller_config[CONF_EMAIL]
password: str = controller_config[CONF_PASSWORD]
unit = controller_config[CONF_UNIT]
unitheating = controller_config[CONF_UNIT_HEATING]
unitwarmwater = controller_config[CONF_UNIT_WARMWATER]
if (
(unit != "" and unit not in UNIT_SUPPORT)
or (unitheating != "" and unitheating not in UNIT_SUPPORT)
or (unitwarmwater != "" and unitwarmwater not in UNIT_SUPPORT)
):
raise Exception(f'unit "{unit}" don\'t supported. Only: {UNIT_SUPPORT} or remove unit: "{unit}"')

if unitheating != "" and unitheating not in UNIT_SUPPORT_HEATING:
raise Exception(f'unit "{unitheating}" don\'t supported. Only: {UNIT_SUPPORT_HEATING} or remove unit: "{unitheating}"')
if unitwarmwater != "" and unitwarmwater not in UNIT_SUPPORT_WARMWATER:
raise Exception(
f'unit "{unitwarmwater}" don\'t supported. Only: {UNIT_SUPPORT_WARMWATER} or remove unit: "{unitwarmwater}"'
)

eco = ista.PyEcotrendIsta(email=email, password=password)
await eco.login()
position = len(hass.data[DOMAIN])
hass.data[CONF_EMAIL].append(email)
hass.data[CONF_PASSWORD].append(password)
hass.data[CONF_UNIT].append(unit)
hass.data[CONF_UNIT_HEATING].append(unitheating)
hass.data[CONF_UNIT_WARMWATER].append(unitwarmwater)
hass.data[CONF_UPDATE_FREQUENCY].append(controller_config[CONF_SCAN_INTERVAL])
Expand Down
3 changes: 2 additions & 1 deletion custom_components/ecotrend_ista/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
CONF_PASSWORD = "password"
CONF_UPDATE_FREQUENCY = "update_frequency"

CONF_UNIT = "unit"
CONF_UNIT = "unit"
CONF_UNIT_HEATING = "unit_heating"
CONF_UNIT_WARMWATER = "unit_warmwater"
Expand All @@ -18,3 +17,5 @@
CONF_TYPE_HEATWATER = "warmwater"

UNIT_SUPPORT = ["kwh"]
UNIT_SUPPORT_HEATING = ["kwh", "Einheiten"]
UNIT_SUPPORT_WARMWATER = ["kwh", "mΒ³"]
9 changes: 7 additions & 2 deletions custom_components/ecotrend_ista/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
import datetime

from typing import Any, Dict, List, Mapping
from typing import Any, Dict, Mapping

from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
from homeassistant.helpers.entity import DeviceInfo
Expand Down Expand Up @@ -32,7 +32,7 @@ def __init__(
self._consum = consum
try:
self._name = "{}".format(self._consum.get("entity_id"))
except:
except Exception:
raise Exception("no entity_id, check your settings or ecotrend-isata has no data")
self._attr_unique_id = self._name
self._attr_last_reset = datetime.datetime.now()
Expand Down Expand Up @@ -78,3 +78,8 @@ def extra_state_attributes(self) -> Mapping[str, Any] | None:
"unitkwh": self._consum.get("unitkwh", ""),
"valuekwh": float(str(self._consum.get("valuekwh", "-1")).replace(",", ".")),
}

@property
def device_class(self) -> str | None:
"""Return the class of this device, from component DEVICE_CLASSES."""
return self.entity_description.key
2 changes: 1 addition & 1 deletion custom_components/ecotrend_ista/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "ecotrend_ista",
"name": "ecotrend ista",
"version": "v1.0.7-beta-2",
"version": "v1.0.7-beta-3",
"documentation": "https://github.com/Ludy87/ecotrend-ista/tree/main",
"issue_tracker": "https://github.com/Ludy87/ecotrend-ista/issues",
"dependencies": [],
Expand Down
56 changes: 20 additions & 36 deletions custom_components/ecotrend_ista/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from .entity import EcoEntity

from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
SensorStateClass,
Expand All @@ -25,13 +24,14 @@
CONF_CONTROLLER,
CONF_TYPE_HEATING,
CONF_TYPE_HEATWATER,
CONF_UNIT,
CONF_UNIT_HEATING,
CONF_UNIT_WARMWATER,
CONF_UPDATE_FREQUENCY,
CONF_YEAR,
CONF_YEARMONTH,
DOMAIN,
UNIT_SUPPORT_HEATING,
UNIT_SUPPORT_WARMWATER,
)

from pyecotrend_ista import pyecotrend_ista as ista
Expand All @@ -43,7 +43,7 @@
key=CONF_TYPE_HEATWATER,
name="Warmwasser",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY,
device_class=CONF_TYPE_HEATWATER,
state_class=SensorStateClass.TOTAL,
entity_category=EntityCategory.DIAGNOSTIC,
icon="mdi:water",
Expand All @@ -52,7 +52,7 @@
key=CONF_TYPE_HEATING,
name="Heizung",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY,
device_class=CONF_TYPE_HEATING,
state_class=SensorStateClass.TOTAL,
entity_category=EntityCategory.DIAGNOSTIC,
icon="mdi:radiator",
Expand All @@ -70,7 +70,6 @@ async def async_setup_platform(
return
controller: ista.PyEcotrendIsta = hass.data[DOMAIN][discovery_info[CONF_CONTROLLER]]
_LOGGER.debug(f"PyEcotrendIsta version: {controller.getVersion()}")
unit = hass.data[CONF_UNIT][discovery_info[CONF_CONTROLLER]]
unitheating = hass.data[CONF_UNIT_HEATING][discovery_info[CONF_CONTROLLER]]
unitwarmwater = hass.data[CONF_UNIT_WARMWATER][discovery_info[CONF_CONTROLLER]]
updateTime = hass.data[CONF_UPDATE_FREQUENCY][discovery_info[CONF_CONTROLLER]]
Expand All @@ -88,21 +87,23 @@ async def async_setup_platform(
support_types: List[str] = await controller.getTypes()
_LOGGER.debug(f"PyEcotrendIsta supported types: {support_types}")

def setUnit():
unit_type = CONF_UNIT_HEATING.split("_")[1]
if unit_type == description.key:
unit = "" if unitheating == UNIT_SUPPORT_HEATING[1] else unitheating
unit_type = CONF_UNIT_WARMWATER.split("_")[1]
if unit_type == description.key:
unit = "" if unitwarmwater == UNIT_SUPPORT_WARMWATER[1] else unitwarmwater
return unit

for description in SENSOR_TYPES:
if consums:
for consum in consums:
if description.key == consum.get("type", ""):
if unitheating != "":
unit_type = CONF_UNIT_HEATING.split("_")[1]
if unit_type == description.key:
unit = unitheating
if unitwarmwater != "":
unit_type = CONF_UNIT_WARMWATER.split("_")[1]
if unit_type == description.key:
unit = unitwarmwater
if not device_id or consum.get("entity_id", "") not in device_id:
entities.append(EcoSensor(controller, description, consum, updateTime, unit))
entities.append(EcoSensor(controller, description, consum, updateTime, setUnit()))
device_id.append(consum.get("entity_id", ""))
_LOGGER.debug("load consums")
if yearmonth:
for ym in yearmonth:
ymL: List[str] = ym.split(".")
Expand All @@ -117,17 +118,9 @@ async def async_setup_platform(
) # warmwasser_yyyy_m_xxxxxxxxx
if consumsyearmonth:
if description.key == consumsyearmonth.get("type", ""):
if unitheating != "":
unit_type = CONF_UNIT_HEATING.split("_")[1]
if unit_type == description.key:
unit = unitheating
if unitwarmwater != "":
unit_type = CONF_UNIT_WARMWATER.split("_")[1]
if unit_type == description.key:
unit = unitwarmwater
if not device_id or consumsyearmonth.get("entity_id", "") not in device_id:
entities.append(
EcoYearMonthSensor(controller, description, consumsyearmonth, updateTime, yyyy, m, unit)
EcoYearMonthSensor(controller, description, consumsyearmonth, updateTime, yyyy, m, setUnit())
)
device_id.append(consumsyearmonth.get("entity_id", ""))
_LOGGER.debug("load yearmonth")
Expand All @@ -136,19 +129,10 @@ async def async_setup_platform(
consumsyear: List[Dict[str, Any]] = await controller.getConsumsByYear(y)
if consumsyear:
for consum in consumsyear:
if consum:
if description.key == consum.get("type", ""):
if unitheating != "":
unit_type = CONF_UNIT_HEATING.split("_")[1]
if unit_type == description.key:
unit = unitheating
if unitwarmwater != "":
unit_type = CONF_UNIT_WARMWATER.split("_")[1]
if unit_type == description.key:
unit = unitwarmwater
if not device_id or consum.get("entity_id", "") not in device_id:
entities.append(EcoYearSensor(controller, description, consum, updateTime, y, unit))
device_id.append(consum.get("entity_id", ""))
if description.key == consum.get("type", ""):
if not device_id or consum.get("entity_id", "") not in device_id:
entities.append(EcoYearSensor(controller, description, consum, updateTime, y, setUnit()))
device_id.append(consum.get("entity_id", ""))
_LOGGER.debug("load year")

add_entities(entities, True)
Expand Down

0 comments on commit 2a9b83f

Please sign in to comment.