Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
magnuselden authored and magnuselden committed Jul 7, 2024
1 parent 12d0f71 commit 44ea8ee
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions custom_components/peaqev/sensors/integration_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@
if TYPE_CHECKING:
from custom_components.peaqev.peaqservice.hub.hub import HomeAssistantHub

from homeassistant.components.integration.const import ( # pylint: disable=import-error
METHOD_LEFT, METHOD_TRAPEZOIDAL)
from homeassistant.components.integration.sensor import \
IntegrationSensor # pylint: disable=import-error
from homeassistant.components.sensor import \
SensorDeviceClass # pylint: disable=import-error
from homeassistant.const import ( # pylint: disable=import-error
ENERGY_KILO_WATT_HOUR, UnitOfTime)
from homeassistant.components.integration.const import METHOD_TRAPEZOIDAL
from homeassistant.components.integration.sensor import IntegrationSensor # pylint: disable=import-error
from homeassistant.components.sensor import SensorDeviceClass # pylint: disable=import-error
from homeassistant.const import (ENERGY_KILO_WATT_HOUR, UnitOfTime)

import custom_components.peaqev.peaqservice.util.extensionmethods as ex
from custom_components.peaqev.const import DOMAIN
Expand All @@ -23,17 +19,18 @@ class PeaqIntegrationCostSensor(IntegrationSensor):
def __init__(self, hub: HomeAssistantHub, name, entry_id):
self._entry_id = entry_id
self.hub = hub
self._attr_name = f"{self.hub.hubname} {name}"
self._attr_name = f'{self.hub.hubname} {name}'
self._attr_unit_of_measurement = ENERGY_KILO_WATT_HOUR

super().__init__(
integration_method=METHOD_TRAPEZOIDAL,
name=self._attr_name,
round_digits=5,
source_entity=f"sensor.{hub.hubname.lower()}_wattage_cost",
source_entity=f'sensor.{hub.hubname.lower()}_wattage_cost',
unique_id=self.unique_id,
unit_prefix="k",
unit_prefix='k',
unit_time=UnitOfTime.HOURS,
max_sub_interval=None
)

@property
Expand All @@ -52,19 +49,19 @@ def entity_registry_visible_default(self) -> bool:
@property
def unique_id(self):
"""Return a unique ID to use for this sensor."""
return f"{DOMAIN}_{self._entry_id}_{ex.nametoid(self._attr_name)}"
return f'{DOMAIN}_{self._entry_id}_{ex.nametoid(self._attr_name)}'

@property
def device_info(self):
"""Return information to link this entity with the correct device."""
return {"identifiers": {(DOMAIN, self.hub.hub_id, POWERCONTROLS)}}
return {'identifiers': {(DOMAIN, self.hub.hub_id, POWERCONTROLS)}}


class PeaqIntegrationSensor(IntegrationSensor):
def __init__(self, hub, sensor, name, entry_id):
self._entry_id = entry_id
self.hub = hub
self._attr_name = f"{self.hub.hubname} {name}"
self._attr_name = f'{self.hub.hubname} {name}'
self._attr_unit_of_measurement = ENERGY_KILO_WATT_HOUR

super().__init__(
Expand All @@ -73,7 +70,7 @@ def __init__(self, hub, sensor, name, entry_id):
round_digits=2,
source_entity=sensor,
unique_id=self.unique_id,
unit_prefix="k",
unit_prefix='k',
unit_time=UnitOfTime.HOURS,
)

Expand All @@ -93,9 +90,9 @@ def entity_registry_visible_default(self) -> bool:
@property
def unique_id(self):
"""Return a unique ID to use for this sensor."""
return f"{DOMAIN}_{self._entry_id}_{ex.nametoid(self._attr_name)}"
return f'{DOMAIN}_{self._entry_id}_{ex.nametoid(self._attr_name)}'

@property
def device_info(self):
"""Return information to link this entity with the correct device."""
return {"identifiers": {(DOMAIN, self.hub.hub_id, POWERCONTROLS)}}
return {'identifiers': {(DOMAIN, self.hub.hub_id, POWERCONTROLS)}}

0 comments on commit 44ea8ee

Please sign in to comment.