Skip to content

Commit

Permalink
feat(sensors): Updated sensors to appear in disabled state if account…
Browse files Browse the repository at this point in the history
… info determines no smart meter is present
  • Loading branch information
BottlecapDave committed Jun 3, 2023
1 parent c1c031a commit b1f123a
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 82 deletions.
218 changes: 176 additions & 42 deletions _docs/setup_account.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ def __init__(self, hass: HomeAssistant, coordinator, tariff_code, meter, point):
self._last_reset = None
self._hass = hass

@property
def entity_registry_enabled_default(self) -> bool:
"""Return if the entity should be enabled when first added.
This only applies when fist added to the entity registry.
"""
return self._is_smart_meter

@property
def unique_id(self):
"""The id of the sensor."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ def __init__(self, hass: HomeAssistant, coordinator, tariff_code, meter, point):
self._state = None
self._last_reset = None

@property
def entity_registry_enabled_default(self) -> bool:
"""Return if the entity should be enabled when first added.
This only applies when fist added to the entity registry.
"""
return self._is_smart_meter

@property
def unique_id(self):
"""The id of the sensor."""
Expand Down
1 change: 1 addition & 0 deletions custom_components/octopus_energy/gas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(self, hass: HomeAssistant, meter, point):

self._mprn = point["mprn"]
self._serial_number = meter["serial_number"]
self._is_smart_meter = meter["is_smart_meter"]

self._attributes = {
"mprn": self._mprn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ def __init__(self, hass: HomeAssistant, coordinator, tariff_code, meter, point,
self._last_reset = None
self._calorific_value = calorific_value

@property
def entity_registry_enabled_default(self) -> bool:
"""Return if the entity should be enabled when first added.
This only applies when fist added to the entity registry.
"""
return self._is_smart_meter

@property
def unique_id(self):
"""The id of the sensor."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ def __init__(self, hass: HomeAssistant, coordinator, tariff_code, meter, point,
self._last_reset = None
self._calorific_value = calorific_value

@property
def entity_registry_enabled_default(self) -> bool:
"""Return if the entity should be enabled when first added.
This only applies when fist added to the entity registry.
"""
return self._is_smart_meter

@property
def unique_id(self):
"""The id of the sensor."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ def __init__(self, hass: HomeAssistant, coordinator, tariff_code, meter, point,
self._last_reset = None
self._calorific_value = calorific_value

@property
def entity_registry_enabled_default(self) -> bool:
"""Return if the entity should be enabled when first added.
This only applies when fist added to the entity registry.
"""
return self._is_smart_meter

@property
def unique_id(self):
"""The id of the sensor."""
Expand Down
78 changes: 38 additions & 40 deletions custom_components/octopus_energy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,28 +94,27 @@ async def async_setup_default_sensors(hass: HomeAssistant, entry, async_add_enti
entities.append(OctopusEnergyElectricityNextRate(hass, electricity_rate_coordinator, meter, point))
entities.append(OctopusEnergyElectricityCurrentStandingCharge(hass, client, electricity_tariff_code, meter, point))

if meter["is_smart_meter"] == True:
previous_consumption_coordinator = await async_create_previous_consumption_and_rates_coordinator(
hass,
client,
point["mpan"],
meter["serial_number"],
True,
electricity_tariff_code,
meter["is_smart_meter"]
)
entities.append(OctopusEnergyPreviousAccumulativeElectricityConsumption(hass, previous_consumption_coordinator, electricity_tariff_code, meter, point))
entities.append(OctopusEnergyPreviousAccumulativeElectricityConsumptionPeak(hass, previous_consumption_coordinator, electricity_tariff_code, meter, point))
entities.append(OctopusEnergyPreviousAccumulativeElectricityConsumptionOffPeak(hass, previous_consumption_coordinator, electricity_tariff_code, meter, point))
entities.append(OctopusEnergyPreviousAccumulativeElectricityCost(hass, previous_consumption_coordinator, electricity_tariff_code, meter, point))
entities.append(OctopusEnergyPreviousAccumulativeElectricityCostPeak(hass, previous_consumption_coordinator, electricity_tariff_code, meter, point))
entities.append(OctopusEnergyPreviousAccumulativeElectricityCostOffPeak(hass, previous_consumption_coordinator, electricity_tariff_code, meter, point))
entities.append(OctopusEnergyPreviousAccumulativeElectricityCostOverride(hass, previous_consumption_coordinator, client, electricity_tariff_code, meter, point))

if meter["is_export"] == False and CONFIG_MAIN_SUPPORTS_LIVE_CONSUMPTION in config and config[CONFIG_MAIN_SUPPORTS_LIVE_CONSUMPTION] == True:
consumption_coordinator = await async_create_current_consumption_coordinator(hass, client, meter["device_id"], True)
entities.append(OctopusEnergyCurrentElectricityConsumption(hass, consumption_coordinator, meter, point))
entities.append(OctopusEnergyCurrentElectricityDemand(hass, consumption_coordinator, meter, point))
previous_consumption_coordinator = await async_create_previous_consumption_and_rates_coordinator(
hass,
client,
point["mpan"],
meter["serial_number"],
True,
electricity_tariff_code,
meter["is_smart_meter"]
)
entities.append(OctopusEnergyPreviousAccumulativeElectricityConsumption(hass, previous_consumption_coordinator, electricity_tariff_code, meter, point))
entities.append(OctopusEnergyPreviousAccumulativeElectricityConsumptionPeak(hass, previous_consumption_coordinator, electricity_tariff_code, meter, point))
entities.append(OctopusEnergyPreviousAccumulativeElectricityConsumptionOffPeak(hass, previous_consumption_coordinator, electricity_tariff_code, meter, point))
entities.append(OctopusEnergyPreviousAccumulativeElectricityCost(hass, previous_consumption_coordinator, electricity_tariff_code, meter, point))
entities.append(OctopusEnergyPreviousAccumulativeElectricityCostPeak(hass, previous_consumption_coordinator, electricity_tariff_code, meter, point))
entities.append(OctopusEnergyPreviousAccumulativeElectricityCostOffPeak(hass, previous_consumption_coordinator, electricity_tariff_code, meter, point))
entities.append(OctopusEnergyPreviousAccumulativeElectricityCostOverride(hass, previous_consumption_coordinator, client, electricity_tariff_code, meter, point))

if meter["is_export"] == False and CONFIG_MAIN_SUPPORTS_LIVE_CONSUMPTION in config and config[CONFIG_MAIN_SUPPORTS_LIVE_CONSUMPTION] == True:
consumption_coordinator = await async_create_current_consumption_coordinator(hass, client, meter["device_id"], True)
entities.append(OctopusEnergyCurrentElectricityConsumption(hass, consumption_coordinator, meter, point))
entities.append(OctopusEnergyCurrentElectricityDemand(hass, consumption_coordinator, meter, point))
else:
for meter in point["meters"]:
_LOGGER.info(f'Skipping electricity meter due to no active agreement; mpan: {point["mpan"]}; serial number: {meter["serial_number"]}')
Expand Down Expand Up @@ -143,24 +142,23 @@ async def async_setup_default_sensors(hass: HomeAssistant, entry, async_add_enti
entities.append(OctopusEnergyGasCurrentRate(hass, rate_coordinator, gas_tariff_code, meter, point, gas_price_cap))
entities.append(OctopusEnergyGasCurrentStandingCharge(hass, client, gas_tariff_code, meter, point))

if meter["is_smart_meter"] == True:
previous_consumption_coordinator = await async_create_previous_consumption_and_rates_coordinator(
hass,
client,
point["mprn"],
meter["serial_number"],
False,
gas_tariff_code,
None
)
entities.append(OctopusEnergyPreviousAccumulativeGasConsumption(hass, previous_consumption_coordinator, gas_tariff_code, meter, point, calorific_value))
entities.append(OctopusEnergyPreviousAccumulativeGasConsumptionKwh(hass, previous_consumption_coordinator, gas_tariff_code, meter, point, calorific_value))
entities.append(OctopusEnergyPreviousAccumulativeGasCost(hass, previous_consumption_coordinator, gas_tariff_code, meter, point, calorific_value))
entities.append(OctopusEnergyPreviousAccumulativeGasCostOverride(hass, previous_consumption_coordinator, client, gas_tariff_code, meter, point, calorific_value))

if CONFIG_MAIN_SUPPORTS_LIVE_CONSUMPTION in config and config[CONFIG_MAIN_SUPPORTS_LIVE_CONSUMPTION] == True:
consumption_coordinator = await async_create_current_consumption_coordinator(hass, client, meter["device_id"], False)
entities.append(OctopusEnergyCurrentGasConsumption(hass, consumption_coordinator, meter, point))
previous_consumption_coordinator = await async_create_previous_consumption_and_rates_coordinator(
hass,
client,
point["mprn"],
meter["serial_number"],
False,
gas_tariff_code,
None
)
entities.append(OctopusEnergyPreviousAccumulativeGasConsumption(hass, previous_consumption_coordinator, gas_tariff_code, meter, point, calorific_value))
entities.append(OctopusEnergyPreviousAccumulativeGasConsumptionKwh(hass, previous_consumption_coordinator, gas_tariff_code, meter, point, calorific_value))
entities.append(OctopusEnergyPreviousAccumulativeGasCost(hass, previous_consumption_coordinator, gas_tariff_code, meter, point, calorific_value))
entities.append(OctopusEnergyPreviousAccumulativeGasCostOverride(hass, previous_consumption_coordinator, client, gas_tariff_code, meter, point, calorific_value))

if CONFIG_MAIN_SUPPORTS_LIVE_CONSUMPTION in config and config[CONFIG_MAIN_SUPPORTS_LIVE_CONSUMPTION] == True:
consumption_coordinator = await async_create_current_consumption_coordinator(hass, client, meter["device_id"], False)
entities.append(OctopusEnergyCurrentGasConsumption(hass, consumption_coordinator, meter, point))
else:
for meter in point["meters"]:
_LOGGER.info(f'Skipping gas meter due to no active agreement; mprn: {point["mprn"]}; serial number: {meter["serial_number"]}')
Expand Down

0 comments on commit b1f123a

Please sign in to comment.