Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue204 #378

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions custom_components/hilo/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from homeassistant.components.utility_meter.sensor import (
async_setup_platform as utility_setup_platform,
)
from homeassistant.helpers.entity_registry import async_get as async_get_registry

from .const import HILO_ENERGY_TOTAL, LOG

Expand All @@ -21,23 +22,28 @@ def __init__(self, hass, period):
self.meter_entities = {}
self.new_entities = 0

def add_meter(self, entity, tariff_list, net_consumption=False):
self.add_meter_entity(entity, tariff_list)
async def entity_exists(self, entity):
"""Check if the entity already exists."""
registry = await async_get_registry(self.hass)
return registry.async_is_registered(entity)

async def add_meter(self, entity, tariff_list, net_consumption=False):
await self.add_meter_entity(entity, tariff_list)
self.add_meter_config(entity, tariff_list, net_consumption)

def add_meter_entity(self, entity, tariff_list):
if entity in self.hass.data.get("utility_meter_data", {}):
async def add_meter_entity(self, entity, tariff_list):
if await self.entity_exists(entity):
LOG.debug(f"Entity {entity} is already in the utility meters")
return
self.new_entities += 1
for tarif in tariff_list:
for tariff in tariff_list:
name = f"{entity}_{self.period}"
meter_name = f"{name} {tarif}"
meter_name = f"{name} {tariff}"
LOG.debug(f"Creating UtilityMeter entity for {entity}: {meter_name}")
self.meter_entities[meter_name] = {
"meter": entity,
"name": meter_name,
"tariff": tarif,
"tariff": tariff,
}

def add_meter_config(self, entity, tariff_list, net_consumption):
Expand Down