Skip to content

Commit

Permalink
Adding net_consumption flag for unknown source tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
valleedelisle committed Feb 4, 2022
1 parent d78ae27 commit cf50c52
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions custom_components/hilo/__init__.py
Expand Up @@ -312,6 +312,7 @@ async def async_init(self, scan_interval: int) -> None:
self.unknown_tracker_device = self.devices.generate_device(
self._get_unknown_source_tracker()
)
self.unknown_tracker_device.net_consumption = True
_async_register_custom_device(
self._hass, self.entry, self.unknown_tracker_device
)
Expand Down
12 changes: 7 additions & 5 deletions custom_components/hilo/managers.py
Expand Up @@ -21,9 +21,9 @@ def __init__(self, hass, period):
self.meter_entities = {}
self.new_entities = 0

def add_meter(self, entity, tariff_list):
def add_meter(self, entity, tariff_list, net_consumption=False):
self.add_meter_entity(entity, tariff_list)
self.add_meter_config(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", {}):
Expand All @@ -40,16 +40,18 @@ def add_meter_entity(self, entity, tariff_list):
"tariff": tarif,
}

def add_meter_config(self, entity, tariff_list):
def add_meter_config(self, entity, tariff_list, net_consumption):
name = f"{entity}_{self.period}"
LOG.debug(f"Creating UtilityMeter config: {name} {tariff_list}")
LOG.debug(
f"Creating UtilityMeter config: {name} {tariff_list} (Net Consumption: {net_consumption})"
)
self.meter_configs[entity] = OrderedDict(
{
"source": f"sensor.{entity}",
"name": name,
"cycle": self.period,
"tariffs": tariff_list,
"net_consumption": False,
"net_consumption": net_consumption,
"utility_meter_sensors": [],
"offset": timedelta(0),
"delta_values": False,
Expand Down
3 changes: 2 additions & 1 deletion custom_components/hilo/sensor.py
Expand Up @@ -156,7 +156,8 @@ def create_energy_entity(device):
if device.type == "Meter":
energy_entity = HILO_ENERGY_TOTAL
tariff_list = validate_tariff_list(tariff_config)
utility_manager.add_meter(energy_entity, tariff_list)
net_consumption = device.net_consumption
utility_manager.add_meter(energy_entity, tariff_list, net_consumption)
energy_manager.add_to_dashboard(energy_entity, tariff_list)

for d in hilo.devices.all:
Expand Down

0 comments on commit cf50c52

Please sign in to comment.