Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions custom_components/myhome/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def __init__(
self._attr_current_humidity = None
self._target_temperature = None
self._local_offset = 0
self._knob_pos = "0"
self._local_target_temperature = None

self._attr_hvac_mode = None
Expand All @@ -193,6 +194,16 @@ def target_temperature(self) -> float:
else:
return self._target_temperature

def extra_state_attributes(self):
"""Restituisce attributi aggiuntivi per il termostato."""
attributes = {}

attributes["local_offset"] = self._local_offset
attributes["local_target_temperature"] = self._local_target_temperature
attributes["knob_pos"] = self._knob_pos

return attributes

async def async_set_hvac_mode(self, hvac_mode):
"""Set new target hvac mode."""
if hvac_mode == HVACMode.OFF:
Expand Down Expand Up @@ -303,6 +314,7 @@ def handle_event(self, message: OWNHeatingEvent):
message.human_readable_log,
)
self._local_offset = message.local_offset
self._knob_pos = message.knob_pos
if self._target_temperature is not None:
self._local_target_temperature = (
self._target_temperature + self._local_offset
Expand Down
115 changes: 93 additions & 22 deletions custom_components/myhome/gateway.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Code to handle a MyHome Gateway."""

import asyncio
from typing import Dict, List

Expand Down Expand Up @@ -149,7 +150,10 @@ async def listening_loop(self):
_event_content.update(message.event_content)
self.hass.bus.async_fire("myhome_message_event", _event_content)
else:
self.hass.bus.async_fire("myhome_message_event", {"gateway": str(self.gateway.host), "message": str(message)})
self.hass.bus.async_fire(
"myhome_message_event",
{"gateway": str(self.gateway.host), "message": str(message)},
)

if not isinstance(message, OWNMessage):
LOGGER.warning(
Expand All @@ -158,13 +162,23 @@ async def listening_loop(self):
message,
)
elif isinstance(message, OWNEnergyEvent):
if SENSOR in self.hass.data[DOMAIN][self.mac][CONF_PLATFORMS] and message.entity in self.hass.data[DOMAIN][self.mac][CONF_PLATFORMS][SENSOR]:
for _entity in self.hass.data[DOMAIN][self.mac][CONF_PLATFORMS][SENSOR][message.entity][CONF_ENTITIES]:
if (
SENSOR in self.hass.data[DOMAIN][self.mac][CONF_PLATFORMS]
and message.entity
in self.hass.data[DOMAIN][self.mac][CONF_PLATFORMS][SENSOR]
):
for _entity in self.hass.data[DOMAIN][self.mac][CONF_PLATFORMS][
SENSOR
][message.entity][CONF_ENTITIES]:
if isinstance(
self.hass.data[DOMAIN][self.mac][CONF_PLATFORMS][SENSOR][message.entity][CONF_ENTITIES][_entity],
self.hass.data[DOMAIN][self.mac][CONF_PLATFORMS][SENSOR][
message.entity
][CONF_ENTITIES][_entity],
MyHOMEEntity,
):
self.hass.data[DOMAIN][self.mac][CONF_PLATFORMS][SENSOR][message.entity][CONF_ENTITIES][_entity].handle_event(message)
self.hass.data[DOMAIN][self.mac][CONF_PLATFORMS][SENSOR][
message.entity
][CONF_ENTITIES][_entity].handle_event(message)
else:
continue
elif (
Expand All @@ -185,7 +199,9 @@ async def listening_loop(self):
{"message": str(message), "event": event},
)
await asyncio.sleep(0.1)
await self.send_status_request(OWNLightingCommand.status("0"))
await self.send_status_request(
OWNLightingCommand.status("0")
)
elif message.is_area:
is_event = True
event = "on" if message.is_on else "off"
Expand All @@ -198,7 +214,9 @@ async def listening_loop(self):
},
)
await asyncio.sleep(0.1)
await self.send_status_request(OWNLightingCommand.status(message.area))
await self.send_status_request(
OWNLightingCommand.status(message.area)
)
elif message.is_group:
is_event = True
event = "on" if message.is_on else "off"
Expand Down Expand Up @@ -256,40 +274,89 @@ async def listening_loop(self):
},
)
if not is_event:
if isinstance(message, OWNLightingEvent) and message.brightness_preset:
if (
isinstance(message, OWNLightingEvent)
and message.brightness_preset
):
if isinstance(
self.hass.data[DOMAIN][self.mac][CONF_PLATFORMS][LIGHT][message.entity][CONF_ENTITIES][LIGHT],
self.hass.data[DOMAIN][self.mac][CONF_PLATFORMS][LIGHT][
message.entity
][CONF_ENTITIES][LIGHT],
MyHOMEEntity,
):
await self.hass.data[DOMAIN][self.mac][CONF_PLATFORMS][LIGHT][message.entity][CONF_ENTITIES][LIGHT].async_update()
await self.hass.data[DOMAIN][self.mac][CONF_PLATFORMS][
LIGHT
][message.entity][CONF_ENTITIES][LIGHT].async_update()
else:
for _platform in self.hass.data[DOMAIN][self.mac][CONF_PLATFORMS]:
if _platform != BUTTON and message.entity in self.hass.data[DOMAIN][self.mac][CONF_PLATFORMS][_platform]:
for _entity in self.hass.data[DOMAIN][self.mac][CONF_PLATFORMS][_platform][message.entity][CONF_ENTITIES]:
for _platform in self.hass.data[DOMAIN][self.mac][
CONF_PLATFORMS
]:
if (
_platform != BUTTON
and message.entity
in self.hass.data[DOMAIN][self.mac][CONF_PLATFORMS][
_platform
]
):
for _entity in self.hass.data[DOMAIN][self.mac][
CONF_PLATFORMS
][_platform][message.entity][CONF_ENTITIES]:
if (
isinstance(
self.hass.data[DOMAIN][self.mac][CONF_PLATFORMS][_platform][message.entity][CONF_ENTITIES][_entity],
self.hass.data[DOMAIN][self.mac][
CONF_PLATFORMS
][_platform][message.entity][
CONF_ENTITIES
][
_entity
],
MyHOMEEntity,
)
and not isinstance(
self.hass.data[DOMAIN][self.mac][CONF_PLATFORMS][_platform][message.entity][CONF_ENTITIES][_entity],
self.hass.data[DOMAIN][self.mac][
CONF_PLATFORMS
][_platform][message.entity][
CONF_ENTITIES
][
_entity
],
DisableCommandButtonEntity,
)
and not isinstance(
self.hass.data[DOMAIN][self.mac][CONF_PLATFORMS][_platform][message.entity][CONF_ENTITIES][_entity],
self.hass.data[DOMAIN][self.mac][
CONF_PLATFORMS
][_platform][message.entity][
CONF_ENTITIES
][
_entity
],
EnableCommandButtonEntity,
)
):
self.hass.data[DOMAIN][self.mac][CONF_PLATFORMS][_platform][message.entity][CONF_ENTITIES][_entity].handle_event(message)
self.hass.data[DOMAIN][self.mac][
CONF_PLATFORMS
][_platform][message.entity][CONF_ENTITIES][
_entity
].handle_event(
message
)

else:
LOGGER.debug(
"%s Ignoring translation message `%s`",
self.log_id,
message,
)
elif isinstance(message, OWNHeatingCommand) and message.dimension is not None and message.dimension == 14:
where = message.where[1:] if message.where.startswith("#") else message.where
elif (
isinstance(message, OWNHeatingCommand)
and message.dimension is not None
and message.dimension == 14
):
where = (
message.where[1:]
if message.where.startswith("#")
else message.where
)
LOGGER.debug(
"%s Received heating command, sending query to zone %s",
self.log_id,
Expand Down Expand Up @@ -344,7 +411,9 @@ async def listening_loop(self):
self.log_id,
message.human_readable_log,
)
elif isinstance(message, OWNGatewayEvent) or isinstance(message, OWNGatewayCommand):
elif isinstance(message, OWNGatewayEvent) or isinstance(
message, OWNGatewayCommand
):
LOGGER.info(
"%s %s",
self.log_id,
Expand Down Expand Up @@ -378,13 +447,15 @@ async def sending_loop(self, worker_id: int):
while not self._terminate_sender:
task = await self.send_buffer.get()
LOGGER.debug(
"%s Message `%s` was successfully unqueued by worker %s.",
"[%s - %s] Message `%s` was successfully unqueued by worker %s.",
self.name,
self.gateway.host,
task["message"],
worker_id,
)
await _command_session.send(message=task["message"], is_status_request=task["is_status_request"])
await _command_session.send(
message=task["message"], is_status_request=task["is_status_request"]
)
self.send_buffer.task_done()

await _command_session.close()
Expand Down