Skip to content

Commit

Permalink
chore: Updated sensors to inherit from RestoreSensor (as recommended …
Browse files Browse the repository at this point in the history
…in docs)
  • Loading branch information
BottlecapDave committed Sep 24, 2023
1 parent cd4d7c4 commit 0faccaa
Show file tree
Hide file tree
Showing 42 changed files with 171 additions and 224 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
CoordinatorEntity
)
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorStateClass,
SensorEntity,
RestoreSensor,
SensorDeviceClass,
SensorStateClass,
)
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.const import (
ENERGY_KILO_WATT_HOUR
)
Expand All @@ -21,12 +20,12 @@

_LOGGER = logging.getLogger(__name__)

class OctopusEnergyCurrentAccumulativeElectricityConsumption(CoordinatorEntity, OctopusEnergyElectricitySensor, SensorEntity, RestoreEntity):
class OctopusEnergyCurrentAccumulativeElectricityConsumption(CoordinatorEntity, OctopusEnergyElectricitySensor, RestoreSensor):
"""Sensor for displaying the current accumulative electricity consumption."""

def __init__(self, hass: HomeAssistant, coordinator, rates_coordinator, standing_charge_coordinator, tariff_code, meter, point):
"""Init sensor."""
super().__init__(coordinator)
CoordinatorEntity.__init__(self, coordinator)
OctopusEnergyElectricitySensor.__init__(self, hass, meter, point)

self._state = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
CoordinatorEntity,
)
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorStateClass,
SensorEntity,
RestoreSensor,
SensorDeviceClass,
SensorStateClass,
)
from homeassistant.helpers.restore_state import RestoreEntity

from homeassistant.const import (
ENERGY_KILO_WATT_HOUR
Expand All @@ -25,12 +24,12 @@

_LOGGER = logging.getLogger(__name__)

class OctopusEnergyCurrentAccumulativeElectricityConsumptionOffPeak(CoordinatorEntity, OctopusEnergyElectricitySensor, SensorEntity, RestoreEntity):
class OctopusEnergyCurrentAccumulativeElectricityConsumptionOffPeak(CoordinatorEntity, OctopusEnergyElectricitySensor, RestoreSensor):
"""Sensor for displaying the current days accumulative electricity reading during off peak hours."""

def __init__(self, hass: HomeAssistant, coordinator, rates_coordinator, standing_charge_coordinator, tariff_code, meter, point):
"""Init sensor."""
super().__init__(coordinator)
CoordinatorEntity.__init__(self, coordinator)
OctopusEnergyElectricitySensor.__init__(self, hass, meter, point)

self._state = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
CoordinatorEntity,
)
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorStateClass,
SensorEntity,
RestoreSensor,
SensorDeviceClass,
SensorStateClass,
)
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.const import (
ENERGY_KILO_WATT_HOUR
)
Expand All @@ -24,12 +23,12 @@

_LOGGER = logging.getLogger(__name__)

class OctopusEnergyCurrentAccumulativeElectricityConsumptionPeak(CoordinatorEntity, OctopusEnergyElectricitySensor, SensorEntity, RestoreEntity):
class OctopusEnergyCurrentAccumulativeElectricityConsumptionPeak(CoordinatorEntity, OctopusEnergyElectricitySensor, RestoreSensor):
"""Sensor for displaying the current days accumulative electricity reading during peak hours."""

def __init__(self, hass: HomeAssistant, coordinator, rates_coordinator, standing_charge_coordinator, tariff_code, meter, point):
"""Init sensor."""
super().__init__(coordinator)
CoordinatorEntity.__init__(self, coordinator)
OctopusEnergyElectricitySensor.__init__(self, hass, meter, point)

self._state = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
CoordinatorEntity,
)
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorStateClass,
SensorEntity,
RestoreSensor,
SensorDeviceClass,
SensorStateClass,
)
from homeassistant.helpers.restore_state import RestoreEntity
from . import (
calculate_electricity_consumption_and_cost,
)
Expand All @@ -20,12 +19,12 @@

_LOGGER = logging.getLogger(__name__)

class OctopusEnergyCurrentAccumulativeElectricityCost(CoordinatorEntity, OctopusEnergyElectricitySensor, SensorEntity, RestoreEntity):
class OctopusEnergyCurrentAccumulativeElectricityCost(CoordinatorEntity, OctopusEnergyElectricitySensor, RestoreSensor):
"""Sensor for displaying the current days accumulative electricity cost."""

def __init__(self, hass: HomeAssistant, coordinator, rates_coordinator, standing_charge_coordinator, tariff_code, meter, point):
"""Init sensor."""
super().__init__(coordinator)
CoordinatorEntity.__init__(self, coordinator)
OctopusEnergyElectricitySensor.__init__(self, hass, meter, point)

self._hass = hass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
CoordinatorEntity,
)
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorStateClass,
SensorEntity,
RestoreSensor,
SensorDeviceClass,
SensorStateClass,
)
from homeassistant.helpers.restore_state import RestoreEntity
from . import (
calculate_electricity_consumption_and_cost,
)
Expand All @@ -20,12 +19,12 @@

_LOGGER = logging.getLogger(__name__)

class OctopusEnergyCurrentAccumulativeElectricityCostOffPeak(CoordinatorEntity, OctopusEnergyElectricitySensor, SensorEntity, RestoreEntity):
class OctopusEnergyCurrentAccumulativeElectricityCostOffPeak(CoordinatorEntity, OctopusEnergyElectricitySensor, RestoreSensor):
"""Sensor for displaying the current days accumulative electricity cost during off peak hours."""

def __init__(self, hass: HomeAssistant, coordinator, rates_coordinator, standing_charge_coordinator, tariff_code, meter, point):
"""Init sensor."""
super().__init__(coordinator)
CoordinatorEntity.__init__(self, coordinator)
OctopusEnergyElectricitySensor.__init__(self, hass, meter, point)

self._state = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
CoordinatorEntity,
)
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorStateClass,
SensorEntity,
RestoreSensor,
SensorDeviceClass,
SensorStateClass,
)
from homeassistant.helpers.restore_state import RestoreEntity
from . import (
calculate_electricity_consumption_and_cost,
)
Expand All @@ -20,12 +19,12 @@

_LOGGER = logging.getLogger(__name__)

class OctopusEnergyCurrentAccumulativeElectricityCostPeak(CoordinatorEntity, OctopusEnergyElectricitySensor, SensorEntity, RestoreEntity):
class OctopusEnergyCurrentAccumulativeElectricityCostPeak(CoordinatorEntity, OctopusEnergyElectricitySensor, RestoreSensor):
"""Sensor for displaying the current days accumulative electricity cost during peak hours."""

def __init__(self, hass: HomeAssistant, coordinator, rates_coordinator, standing_charge_coordinator, tariff_code, meter, point):
"""Init sensor."""
super().__init__(coordinator)
CoordinatorEntity.__init__(self, coordinator)
OctopusEnergyElectricitySensor.__init__(self, hass, meter, point)

self._state = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
CoordinatorEntity
)
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorStateClass,
SensorEntity,
RestoreSensor,
SensorDeviceClass,
SensorStateClass,
)
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.const import (
ENERGY_KILO_WATT_HOUR
)
Expand All @@ -22,12 +21,12 @@

_LOGGER = logging.getLogger(__name__)

class OctopusEnergyCurrentElectricityConsumption(CoordinatorEntity, OctopusEnergyElectricitySensor, SensorEntity, RestoreEntity):
class OctopusEnergyCurrentElectricityConsumption(CoordinatorEntity, OctopusEnergyElectricitySensor, RestoreSensor):
"""Sensor for displaying the current electricity consumption."""

def __init__(self, hass: HomeAssistant, coordinator, meter, point):
"""Init sensor."""
super().__init__(coordinator)
CoordinatorEntity.__init__(self, coordinator)
OctopusEnergyElectricitySensor.__init__(self, hass, meter, point)

self._state = None
Expand Down
11 changes: 5 additions & 6 deletions custom_components/octopus_energy/electricity/current_demand.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,21 @@
CoordinatorEntity
)
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorStateClass,
SensorEntity,
RestoreSensor,
SensorDeviceClass,
SensorStateClass,
)
from homeassistant.helpers.restore_state import RestoreEntity

from .base import (OctopusEnergyElectricitySensor)

_LOGGER = logging.getLogger(__name__)

class OctopusEnergyCurrentElectricityDemand(CoordinatorEntity, OctopusEnergyElectricitySensor, SensorEntity, RestoreEntity):
class OctopusEnergyCurrentElectricityDemand(CoordinatorEntity, OctopusEnergyElectricitySensor, RestoreSensor):
"""Sensor for displaying the current electricity demand."""

def __init__(self, hass: HomeAssistant, coordinator, meter, point):
"""Init sensor."""
super().__init__(coordinator)
CoordinatorEntity.__init__(self, coordinator)
OctopusEnergyElectricitySensor.__init__(self, hass, meter, point)

self._state = None
Expand Down
11 changes: 5 additions & 6 deletions custom_components/octopus_energy/electricity/current_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,24 @@
CoordinatorEntity,
)
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorStateClass,
SensorEntity,
RestoreSensor,
SensorDeviceClass,
SensorStateClass,
)
from homeassistant.helpers.restore_state import RestoreEntity

from .base import (OctopusEnergyElectricitySensor)

from ..utils.rate_information import (get_current_rate_information)

_LOGGER = logging.getLogger(__name__)

class OctopusEnergyElectricityCurrentRate(CoordinatorEntity, OctopusEnergyElectricitySensor, SensorEntity, RestoreEntity):
class OctopusEnergyElectricityCurrentRate(CoordinatorEntity, OctopusEnergyElectricitySensor, RestoreSensor):
"""Sensor for displaying the current rate."""

def __init__(self, hass: HomeAssistant, coordinator, meter, point, tariff_code, electricity_price_cap):
"""Init sensor."""
# Pass coordinator to base class
super().__init__(coordinator)
CoordinatorEntity.__init__(self, coordinator)
OctopusEnergyElectricitySensor.__init__(self, hass, meter, point)

self._state = None
Expand Down
11 changes: 5 additions & 6 deletions custom_components/octopus_energy/electricity/next_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@
CoordinatorEntity
)
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorStateClass,
SensorEntity,
RestoreSensor,
SensorDeviceClass,
SensorStateClass,
)
from homeassistant.helpers.restore_state import RestoreEntity

from .base import (OctopusEnergyElectricitySensor)
from ..utils.rate_information import (get_next_rate_information)

_LOGGER = logging.getLogger(__name__)

class OctopusEnergyElectricityNextRate(CoordinatorEntity, OctopusEnergyElectricitySensor, SensorEntity, RestoreEntity):
class OctopusEnergyElectricityNextRate(CoordinatorEntity, OctopusEnergyElectricitySensor, RestoreSensor):
"""Sensor for displaying the next rate."""

def __init__(self, hass: HomeAssistant, coordinator, meter, point):
"""Init sensor."""
# Pass coordinator to base class
super().__init__(coordinator)
CoordinatorEntity.__init__(self, coordinator)
OctopusEnergyElectricitySensor.__init__(self, hass, meter, point)

self._state = None
Expand Down
2 changes: 1 addition & 1 deletion custom_components/octopus_energy/electricity/off_peak.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class OctopusEnergyElectricityOffPeak(CoordinatorEntity, OctopusEnergyElectricit
def __init__(self, hass: HomeAssistant, coordinator, meter, point):
"""Init sensor."""

super().__init__(coordinator)
CoordinatorEntity.__init__(self, coordinator)
OctopusEnergyElectricitySensor.__init__(self, hass, meter, point)

self._state = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
CoordinatorEntity,
)
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorStateClass,
SensorEntity,
RestoreSensor,
SensorDeviceClass,
SensorStateClass,
)
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.const import (
ENERGY_KILO_WATT_HOUR
)
Expand All @@ -26,12 +25,12 @@

_LOGGER = logging.getLogger(__name__)

class OctopusEnergyPreviousAccumulativeElectricityConsumption(CoordinatorEntity, OctopusEnergyElectricitySensor, SensorEntity, RestoreEntity):
class OctopusEnergyPreviousAccumulativeElectricityConsumption(CoordinatorEntity, OctopusEnergyElectricitySensor, RestoreSensor):
"""Sensor for displaying the previous days accumulative electricity reading."""

def __init__(self, hass: HomeAssistant, coordinator, tariff_code, meter, point):
"""Init sensor."""
super().__init__(coordinator)
CoordinatorEntity.__init__(self, coordinator)
OctopusEnergyElectricitySensor.__init__(self, hass, meter, point)

self._state = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
CoordinatorEntity,
)
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorStateClass,
SensorEntity,
RestoreSensor,
SensorDeviceClass,
SensorStateClass,
)
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.const import (
ENERGY_KILO_WATT_HOUR
)
Expand All @@ -24,12 +23,12 @@

_LOGGER = logging.getLogger(__name__)

class OctopusEnergyPreviousAccumulativeElectricityConsumptionOffPeak(CoordinatorEntity, OctopusEnergyElectricitySensor, SensorEntity, RestoreEntity):
class OctopusEnergyPreviousAccumulativeElectricityConsumptionOffPeak(CoordinatorEntity, OctopusEnergyElectricitySensor, RestoreSensor):
"""Sensor for displaying the previous days accumulative electricity reading during off peak hours."""

def __init__(self, hass: HomeAssistant, coordinator, tariff_code, meter, point):
"""Init sensor."""
super().__init__(coordinator)
CoordinatorEntity.__init__(self, coordinator)
OctopusEnergyElectricitySensor.__init__(self, hass, meter, point)

self._state = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
CoordinatorEntity,
)
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorStateClass,
SensorEntity,
RestoreSensor,
SensorDeviceClass,
SensorStateClass,
)
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.const import (
ENERGY_KILO_WATT_HOUR
)
Expand All @@ -24,12 +23,12 @@

_LOGGER = logging.getLogger(__name__)

class OctopusEnergyPreviousAccumulativeElectricityConsumptionPeak(CoordinatorEntity, OctopusEnergyElectricitySensor, SensorEntity, RestoreEntity):
class OctopusEnergyPreviousAccumulativeElectricityConsumptionPeak(CoordinatorEntity, OctopusEnergyElectricitySensor, RestoreSensor):
"""Sensor for displaying the previous days accumulative electricity reading during peak hours."""

def __init__(self, hass: HomeAssistant, coordinator, tariff_code, meter, point):
"""Init sensor."""
super().__init__(coordinator)
CoordinatorEntity.__init__(self, coordinator)
OctopusEnergyElectricitySensor.__init__(self, hass, meter, point)

self._state = None
Expand Down
Loading

0 comments on commit 0faccaa

Please sign in to comment.