Skip to content

Commit b0ad1bb

Browse files
committed
chore: Reverted exposing to standard sensor
1 parent 5e09826 commit b0ad1bb

File tree

6 files changed

+45
-116
lines changed

6 files changed

+45
-116
lines changed

_docs/services.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ Allows you to set the heat pump configuration for fixed and weather compensated
258258
!!! warning
259259
Changing this configuration without a good understanding of heat loss and emitter output can cause cycling, defrosting, or incorrect heat delivery.
260260

261+
!!! note
262+
Corresponding sensors will not update straight away upon calling.
263+
261264
| Attribute | Optional | Description |
262265
| ------------------------ | -------- | --------------------------------------------------------------------------------------------------------------------- |
263266
| `target.entity_id` | `no` | Any climate entity belonging to the heat pump which the configuration should be applied to (e.g. `climate.octopus_energy_heat_pump_{{HEAT_PUMP_ID}}_{{ZONE_CODE}}`). |

custom_components/octopus_energy/api_client/__init__.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -409,22 +409,6 @@
409409
}}
410410
'''
411411

412-
heat_pump_update_fixed_target_flow_temp_mutation = '''
413-
mutation {{
414-
octoHeatPumpUpdateFlowTemperatureConfiguration(
415-
euid: "{euid}"
416-
flowTemperatureInput: {{
417-
flowTemperature: {{
418-
value: "{fixed_flow_temperature}",
419-
unit: DEGREES_CELSIUS
420-
}}
421-
}}
422-
) {{
423-
transactionId
424-
}}
425-
}}
426-
'''
427-
428412
heat_pump_status_and_config_query = '''
429413
query {{
430414
octoHeatPumpControllerStatus(accountNumber: "{account_id}", euid: "{euid}") {{
@@ -942,23 +926,6 @@ async def async_set_heat_pump_flow_temp_config(self, euid: str, weather_comp_ena
942926
except TimeoutError:
943927
_LOGGER.warning(f'Failed to connect. Timeout of {self._timeout} exceeded.')
944928
raise TimeoutException()
945-
946-
async def async_set_heat_pump_fixed_target_flow_temp(self, euid: str, fixed_flow_temperature: float):
947-
"""Sets the flow temperature for a given heat pump zone"""
948-
await self.async_refresh_token()
949-
950-
try:
951-
client = self._create_client_session()
952-
url = f'{self._base_url}/v1/graphql/'
953-
query = heat_pump_update_fixed_target_flow_temp_mutation.format(euid=euid, fixed_flow_temperature=fixed_flow_temperature)
954-
payload = { "query": query }
955-
headers = { "Authorization": f"JWT {self._graphql_token}" }
956-
async with client.post(url, json=payload, headers=headers) as heat_pump_response:
957-
await self.__async_read_response__(heat_pump_response, url)
958-
959-
except TimeoutError:
960-
_LOGGER.warning(f'Failed to connect. Timeout of {self._timeout} exceeded.')
961-
raise TimeoutException()
962929

963930
async def async_set_heat_pump_zone_mode(self, account_id: str, euid: str, zone_id: str, zone_mode: str, target_temperature: float | None):
964931
"""Sets the mode for a given heat pump zone"""
Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
from datetime import datetime
12
import logging
3+
from typing import List
24

35
from homeassistant.const import (
46
STATE_UNAVAILABLE,
@@ -7,37 +9,34 @@
79
)
810
from homeassistant.core import HomeAssistant, callback
911

12+
from homeassistant.util.dt import (now)
1013
from homeassistant.helpers.update_coordinator import (
1114
CoordinatorEntity
1215
)
13-
from homeassistant.components.number import RestoreNumber, NumberDeviceClass, NumberMode
14-
from homeassistant.util.dt import (now)
16+
from homeassistant.components.sensor import (
17+
RestoreSensor,
18+
SensorDeviceClass,
19+
SensorStateClass,
20+
)
1521

1622
from .base import (BaseOctopusEnergyHeatPumpSensor)
1723
from ..utils.attributes import dict_to_typed_dict
1824
from ..api_client.heat_pump import HeatPump
1925
from ..coordinators.heat_pump_configuration_and_status import HeatPumpCoordinatorResult
20-
from ..api_client import OctopusEnergyApiClient
2126

2227
_LOGGER = logging.getLogger(__name__)
2328

24-
class OctopusEnergyHeatPumpFixedTargetFlowTemperature(CoordinatorEntity, RestoreNumber, BaseOctopusEnergyHeatPumpSensor):
25-
"""Sensor for reading and setting the fixed target flow temperature of a heat pump."""
29+
class OctopusEnergyHeatPumpSensorFixedTargetFlowTemperature(CoordinatorEntity, BaseOctopusEnergyHeatPumpSensor, RestoreSensor):
30+
"""Sensor for displaying the live heat output of a heat pump."""
2631

27-
def __init__(self, hass: HomeAssistant, client: OctopusEnergyApiClient, coordinator, heat_pump_id: str, heat_pump: HeatPump):
32+
def __init__(self, hass: HomeAssistant, coordinator, heat_pump_id: str, heat_pump: HeatPump):
2833
"""Init sensor."""
2934
# Pass coordinator to base class
3035
CoordinatorEntity.__init__(self, coordinator)
31-
BaseOctopusEnergyHeatPumpSensor.__init__(self, hass, heat_pump_id, heat_pump, entity_domain="number")
36+
BaseOctopusEnergyHeatPumpSensor.__init__(self, hass, heat_pump_id, heat_pump)
3237

33-
3438
self._state = None
35-
self._client = client
3639
self._last_updated = None
37-
self._attr_native_min_value = 30
38-
self._attr_native_max_value = 70
39-
self._attr_native_step = 1
40-
self._attr_mode = NumberMode.BOX
4140

4241
@property
4342
def unique_id(self):
@@ -49,45 +48,35 @@ def name(self):
4948
"""Name of the sensor."""
5049
return f"Fixed Target Flow Temperature Heat Pump ({self._heat_pump_id})"
5150

51+
@property
52+
def state_class(self):
53+
"""The state class of sensor"""
54+
return SensorStateClass.MEASUREMENT
55+
5256
@property
5357
def device_class(self):
5458
"""The type of sensor"""
55-
return NumberDeviceClass.TEMPERATURE
56-
59+
return SensorDeviceClass.TEMPERATURE
60+
61+
@property
62+
def icon(self):
63+
"""Icon of the sensor."""
64+
return "mdi:thermometer"
65+
5766
@property
5867
def native_unit_of_measurement(self):
59-
"""The unit of measurement of sensor"""
68+
"""Unit of measurement of the sensor."""
6069
return UnitOfTemperature.CELSIUS
6170

6271
@property
6372
def extra_state_attributes(self):
6473
"""Attributes of the sensor."""
6574
return self._attributes
66-
75+
6776
@property
68-
def native_value(self) -> float:
77+
def native_value(self):
6978
return self._state
7079

71-
async def async_set_native_value(self, value: float) -> None:
72-
"""Set new value."""
73-
if value and value % self._attr_native_step == 0:
74-
try:
75-
await self._client.async_set_heat_pump_fixed_target_flow_temp(
76-
self._heat_pump_id,
77-
value
78-
)
79-
except Exception as e:
80-
if self._is_mocked:
81-
_LOGGER.warning(f'Suppress async_set_native_value error due to mocking mode: {e}')
82-
else:
83-
raise
84-
85-
self._state = value
86-
self._last_updated = now()
87-
self.async_write_ha_state()
88-
else:
89-
raise Exception(f"Value must be between {self._attr_native_min_value} and {self._attr_native_max_value} and be a multiple of {self._attr_native_step}")
90-
9180
@callback
9281
def _handle_coordinator_update(self) -> None:
9382
"""Retrieve the configured fixed target flow temperature for the heat pump."""
@@ -100,7 +89,7 @@ def _handle_coordinator_update(self) -> None:
10089
and result.data.octoHeatPumpControllerConfiguration.heatPump is not None
10190
and result.data.octoHeatPumpControllerConfiguration.heatPump.heatingFlowTemperature is not None
10291
and result.data.octoHeatPumpControllerConfiguration.heatPump.heatingFlowTemperature.currentTemperature is not None):
103-
_LOGGER.debug(f"Updating OctopusEnergyHeatPumpNumberFixedTargetFlowTemperature for '{self._heat_pump_id}'")
92+
_LOGGER.debug(f"Updating OctopusEnergyHeatPumpSensorFixedTargetFlowTemperature for '{self._heat_pump_id}'")
10493

10594
self._state = float(result.data.octoHeatPumpControllerConfiguration.heatPump.heatingFlowTemperature.currentTemperature.value)
10695
self._last_updated = current
@@ -119,4 +108,4 @@ async def async_added_to_hass(self):
119108
self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value
120109
self._attributes = dict_to_typed_dict(state.attributes, [])
121110

122-
_LOGGER.debug(f'Restored OctopusEnergyHeatPumpNumberFixedTargetFlowTemperature state: {self._state}')
111+
_LOGGER.debug(f'Restored OctopusEnergyHeatPumpSensorFixedTargetFlowTemperature state: {self._state}')

custom_components/octopus_energy/heat_pump/water_heater.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ async def async_set_operation_mode(self, operation_mode: str):
154154
await self._client.async_set_heat_pump_zone_mode(self._account_id, self._heat_pump_id, self._zone.configuration.code, zone_mode, None)
155155
except Exception as e:
156156
if self._is_mocked:
157-
_LOGGER.warning(f'Suppress async_set_preset_mode error due to mocking mode: {e}')
157+
_LOGGER.warning(f'Suppress async_set_operation_mode error due to mocking mode: {e}')
158158
else:
159159
raise
160160

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import logging
22

3-
from .api_client import OctopusEnergyApiClient
4-
from .api_client.heat_pump import HeatPumpResponse
5-
from .heat_pump import get_mock_heat_pump_id
6-
from .heat_pump.sensor_fixed_target_flow_temperature import OctopusEnergyHeatPumpFixedTargetFlowTemperature
73

84
from .utils.debug_overrides import async_get_account_debug_override
95

@@ -13,10 +9,7 @@
139

1410
from .const import (
1511
CONFIG_ACCOUNT_ID,
16-
DATA_ACCOUNT,
1712
DATA_CLIENT,
18-
DATA_HEAT_PUMP_CONFIGURATION_AND_STATUS_COORDINATOR,
19-
DATA_HEAT_PUMP_CONFIGURATION_AND_STATUS_KEY,
2013
DATA_INTELLIGENT_DEVICE,
2114
DOMAIN,
2215

@@ -38,29 +31,13 @@ async def async_setup_entry(hass, entry, async_add_entities):
3831
entities = []
3932

4033
if CONFIG_MAIN_API_KEY in entry.data:
41-
entities.extend(await async_setup_intelligent_sensors(hass, config, async_add_entities))
42-
43-
account_id = config[CONFIG_ACCOUNT_ID]
44-
client = hass.data[DOMAIN][account_id][DATA_CLIENT]
45-
account_debug_override = await async_get_account_debug_override(hass, account_id)
46-
account_result = hass.data[DOMAIN][account_id][DATA_ACCOUNT]
47-
account_info = account_result.account if account_result is not None else None
48-
49-
mock_heat_pump = account_debug_override.mock_heat_pump if account_debug_override is not None else False
50-
if mock_heat_pump:
51-
heat_pump_id = get_mock_heat_pump_id()
52-
key = DATA_HEAT_PUMP_CONFIGURATION_AND_STATUS_KEY.format(heat_pump_id)
53-
coordinator = hass.data[DOMAIN][account_id][DATA_HEAT_PUMP_CONFIGURATION_AND_STATUS_COORDINATOR.format(heat_pump_id)]
54-
entities(setup_heat_pump_sensors(hass, client, heat_pump_id, hass.data[DOMAIN][account_id][key].data, coordinator))
55-
elif "heat_pump_ids" in account_info:
56-
for heat_pump_id in account_info["heat_pump_ids"]:
57-
key = DATA_HEAT_PUMP_CONFIGURATION_AND_STATUS_KEY.format(heat_pump_id)
58-
coordinator = hass.data[DOMAIN][account_id][DATA_HEAT_PUMP_CONFIGURATION_AND_STATUS_COORDINATOR.format(heat_pump_id)]
59-
entities(setup_heat_pump_sensors(hass, client, heat_pump_id, hass.data[DOMAIN][account_id][key].data, coordinator))
34+
entities.extend(await async_setup_intelligent_sensors(hass, config))
35+
36+
async_add_entities(entities)
6037

6138
return True
6239

63-
async def async_setup_intelligent_sensors(hass, config, async_add_entities):
40+
async def async_setup_intelligent_sensors(hass, config):
6441
_LOGGER.debug('Setting up intelligent sensors')
6542

6643
entities = []
@@ -78,19 +55,4 @@ async def async_setup_intelligent_sensors(hass, config, async_add_entities):
7855
if intelligent_features.charge_limit_supported == True:
7956
entities.append(OctopusEnergyIntelligentChargeTarget(hass, settings_coordinator, client, intelligent_device, account_id, account_debug_override.mock_intelligent_controls if account_debug_override is not None else False))
8057

81-
async_add_entities(entities)
82-
83-
def setup_heat_pump_sensors(hass, client: OctopusEnergyApiClient, heat_pump_id: str, heat_pump_response: HeatPumpResponse, coordinator):
84-
85-
entities = []
86-
87-
if heat_pump_response is not None and heat_pump_response.octoHeatPumpControllerConfiguration is not None:
88-
entities.append(OctopusEnergyHeatPumpFixedTargetFlowTemperature(
89-
hass,
90-
client,
91-
coordinator,
92-
heat_pump_id,
93-
heat_pump_response.octoHeatPumpControllerConfiguration.heatPump
94-
))
95-
9658
return entities

custom_components/octopus_energy/sensor.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
from .heat_pump.sensor_lifetime_scop import OctopusEnergyHeatPumpSensorLifetimeSCoP
6969
from .heat_pump.sensor_lifetime_heat_output import OctopusEnergyHeatPumpSensorLifetimeHeatOutput
7070
from .heat_pump.sensor_lifetime_energy_input import OctopusEnergyHeatPumpSensorLifetimeEnergyInput
71+
from .heat_pump.sensor_fixed_target_flow_temperature import OctopusEnergyHeatPumpSensorFixedTargetFlowTemperature
7172
from .api_client.intelligent_device import IntelligentDevice
7273
from .intelligent.current_state import OctopusEnergyIntelligentCurrentState
7374
from .intelligent import get_intelligent_features
@@ -598,6 +599,13 @@ def setup_heat_pump_sensors(hass: HomeAssistant, account_id: str, heat_pump_id:
598599
entities.append(OctopusEnergyHeatPumpDataLastRetrieved(hass, coordinator, account_id, heat_pump_id))
599600

600601
if heat_pump_response.octoHeatPumpControllerConfiguration is not None:
602+
entities.append(OctopusEnergyHeatPumpSensorFixedTargetFlowTemperature(
603+
hass,
604+
coordinator,
605+
heat_pump_id,
606+
heat_pump_response.octoHeatPumpControllerConfiguration.heatPump
607+
))
608+
601609
for zone in heat_pump_response.octoHeatPumpControllerConfiguration.zones:
602610
if zone.configuration is not None and zone.configuration.sensors is not None:
603611
if zone.configuration.enabled == False:

0 commit comments

Comments
 (0)