1 """Support for OSO Energy water heaters."""
6 from apyosoenergyapi
import OSOEnergy
7 from apyosoenergyapi.helper.const
import OSOEnergyWaterHeaterData
8 import voluptuous
as vol
16 WaterHeaterEntityFeature,
26 from .const
import DOMAIN
27 from .entity
import OSOEnergyEntity
29 ATTR_UNTIL_TEMP_LIMIT =
"until_temp_limit"
30 ATTR_V40MIN =
"v40_min"
31 CURRENT_OPERATION_MAP: dict[str, Any] = {
34 "powersave": STATE_OFF,
35 "extraenergy": STATE_HIGH_DEMAND,
40 "powersave": STATE_OFF,
41 "extraenergy": STATE_HIGH_DEMAND,
44 SERVICE_GET_PROFILE =
"get_profile"
45 SERVICE_SET_PROFILE =
"set_profile"
46 SERVICE_SET_V40MIN =
"set_v40_min"
47 SERVICE_TURN_OFF =
"turn_off"
48 SERVICE_TURN_ON =
"turn_on"
52 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
54 """Set up OSO Energy heater based on a config entry."""
55 osoenergy = hass.data[DOMAIN][entry.entry_id]
56 devices = osoenergy.session.device_list.get(
"water_heater")
61 platform = entity_platform.async_get_current_platform()
63 platform.async_register_entity_service(
66 OSOEnergyWaterHeater.async_get_profile.__name__,
67 supports_response=SupportsResponse.ONLY,
70 service_set_profile_schema = cv.make_entity_service_schema(
72 vol.Optional(f
"hour_{hour:02d}"): vol.All(
73 vol.Coerce(int), vol.Range(min=10, max=75)
79 platform.async_register_entity_service(
81 service_set_profile_schema,
82 OSOEnergyWaterHeater.async_set_profile.__name__,
85 platform.async_register_entity_service(
88 vol.Required(ATTR_V40MIN): vol.All(
89 vol.Coerce(float), vol.Range(min=200, max=550)
92 OSOEnergyWaterHeater.async_set_v40_min.__name__,
95 platform.async_register_entity_service(
97 {vol.Required(ATTR_UNTIL_TEMP_LIMIT): vol.All(cv.boolean)},
98 OSOEnergyWaterHeater.async_oso_turn_off.__name__,
101 platform.async_register_entity_service(
103 {vol.Required(ATTR_UNTIL_TEMP_LIMIT): vol.All(cv.boolean)},
104 OSOEnergyWaterHeater.async_oso_turn_on.__name__,
109 """Convert the requested local hour to a utc hour for the day.
112 local_hour: the local hour (0-23) for the current day to be converted.
115 Datetime representation for the requested hour in utc time for the day.
119 local_time = now.replace(hour=local_hour, minute=0, second=0, microsecond=0)
120 return dt_util.as_utc(local_time)
124 """Convert the requested utc hour to a local hour for the day.
127 utc_hour: the utc hour (0-23) for the current day to be converted.
130 Datetime representation for the requested hour in local time for the day.
133 utc_now = dt_util.utcnow()
134 utc_time = utc_now.replace(hour=utc_hour, minute=0, second=0, microsecond=0)
135 return dt_util.as_local(utc_time)
139 """Convert UTC profile to local.
141 Receives a device temperature schedule - 24 values for the day where the index represents the hour of the day in UTC.
142 Converts the schedule to local time.
145 values: list of floats representing the 24 hour temperature schedule for the device
147 The device temperature schedule in local time.
150 profile: list[JsonValueType] = [0.0] * 24
151 for hour
in range(24):
153 profile[local_hour.hour] =
float(values[hour])
159 OSOEnergyEntity[OSOEnergyWaterHeaterData], WaterHeaterEntity
161 """OSO Energy Water Heater Device."""
164 _attr_supported_features = (
165 WaterHeaterEntityFeature.TARGET_TEMPERATURE | WaterHeaterEntityFeature.ON_OFF
167 _attr_temperature_unit = UnitOfTemperature.CELSIUS
172 entity_data: OSOEnergyWaterHeaterData,
174 """Initialize the OSO Energy water heater."""
175 super().
__init__(instance, entity_data)
180 """Return if the device is available."""
185 """Return current operation."""
186 status = self.
entity_dataentity_data.current_operation
190 optimization_mode = self.
entity_dataentity_data.optimization_mode.lower()
191 heater_mode = self.
entity_dataentity_data.heater_mode.lower()
192 if optimization_mode
in CURRENT_OPERATION_MAP:
193 return CURRENT_OPERATION_MAP[optimization_mode].
get(
194 heater_mode, STATE_ELECTRIC
197 return CURRENT_OPERATION_MAP[
"default"].
get(heater_mode, STATE_ELECTRIC)
201 """Return the current temperature of the heater."""
202 return self.
entity_dataentity_data.current_temperature
206 """Return the temperature we try to reach."""
207 return self.
entity_dataentity_data.target_temperature
211 """Return the temperature we try to reach."""
212 return self.
entity_dataentity_data.target_temperature_high
216 """Return the temperature we try to reach."""
217 return self.
entity_dataentity_data.target_temperature_low
221 """Return the minimum temperature."""
226 """Return the maximum temperature."""
230 """Turn on hotwater."""
231 await self.osoenergy.hotwater.turn_on(self.
entity_dataentity_data,
True)
234 """Turn off hotwater."""
235 await self.osoenergy.hotwater.turn_off(self.
entity_dataentity_data,
True)
238 """Set new target temperature."""
240 profile = [target_temperature] * 24
242 await self.osoenergy.hotwater.set_profile(self.
entity_dataentity_data, profile)
245 """Return the current temperature profile of the device."""
251 """Handle the service call."""
254 for hour
in range(24):
255 hour_key = f
"hour_{hour:02d}"
257 if hour_key
in kwargs:
260 await self.osoenergy.hotwater.set_profile(self.
entity_dataentity_data, profile)
263 """Handle the service call."""
264 await self.osoenergy.hotwater.set_v40_min(self.
entity_dataentity_data, v40_min)
267 """Handle the service call."""
268 await self.osoenergy.hotwater.turn_off(self.
entity_dataentity_data, until_temp_limit)
271 """Handle the service call."""
272 await self.osoenergy.hotwater.turn_on(self.
entity_dataentity_data, until_temp_limit)
275 """Update all Node data from Hive."""
276 await self.osoenergy.session.update_data()
277 self.
entity_dataentity_data = await self.osoenergy.hotwater.get_water_heater(
None __init__(self, OSOEnergy instance, OSOEnergyWaterHeaterData entity_data)
float target_temperature(self)
None async_turn_on(self, **kwargs)
None async_set_temperature(self, **Any kwargs)
str current_operation(self)
None async_oso_turn_off(self, until_temp_limit)
None async_set_v40_min(self, v40_min)
float current_temperature(self)
float target_temperature_low(self)
None async_oso_turn_on(self, until_temp_limit)
ServiceResponse async_get_profile(self)
None async_turn_off(self, **kwargs)
None async_set_profile(self, **Any kwargs)
float target_temperature_high(self)
float|None target_temperature(self)
web.Response get(self, web.Request request, str config_key)
dt.datetime _get_local_hour(int utc_hour)
list[JsonValueType] _convert_profile_to_local(list[float] values)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
dt.datetime _get_utc_hour(int local_hour)