Skip to content

Commit

Permalink
Merge pull request #323 from asantaga/dev
Browse files Browse the repository at this point in the history
v3.2.2
  • Loading branch information
msp1974 authored Nov 4, 2022
2 parents 0f6d95c + f1e0bce commit 6549411
Show file tree
Hide file tree
Showing 15 changed files with 976 additions and 554 deletions.
77 changes: 74 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Wiser Home Assistant Integration v3.2.1
# Wiser Home Assistant Integration v3.2.2

[![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg?style=for-the-badge)](https://github.com/hacs/integration)
[![downloads](https://shields.io/github/downloads/asantaga/wiserHomeAssistantPlatform/latest/total?style=for-the-badge)](https://github.com/asantaga/wiserHomeAssistantPlatform)
Expand All @@ -21,7 +21,9 @@ For more information checkout the AMAZING community thread available on
- Quite a bit of code tidying and black formatting

- Schedule files now support the All special day as well as Weekdays and Weekends.
- New service to set a schedule from a string that supports templating. See [set_schedule_from_string](https://github.com/asantaga/wiserHomeAssistantPlatform/blob/master/docs/services.md#set-schedule-from-string)
- New service to set a schedule from a string that supports templating. See [Set Schedule From String](https://github.com/asantaga/wiserHomeAssistantPlatform/blob/master/docs/services.md#set-schedule-from-string)
- Schedule card options to show IDs and list view
- Events and automation triggers. See [Events & Triggers](#events--triggers)

## Contents

Expand All @@ -31,6 +33,7 @@ For more information checkout the AMAZING community thread available on
- [Providing You Hub Output as a JSON File](#providing-your-hub-output-as-a-json-file)
- [Functionality of this Integration](#functionality)
- [Services Included in this Integration](https://github.com/asantaga/wiserHomeAssistantPlatform/blob/master/docs/services.md)
- [Events & Triggers](#events--triggers)
- [Installing](#code-installation)
- [Configuration](#configuration)
- [Managing Schedules with Home Assistant](#managing-schedules-with-home-assistant)
Expand Down Expand Up @@ -149,7 +152,11 @@ In order to download this file do the following:
- Service `get_schedule/set_schedule/copy_schedule/assign_schedule`: Provides ability to get/set/copy/assign schedules for rooms, hotwater, lights and shutters
- Service `set_device_mode`: Provides ability to set the mode of a specific smartplug, hot water, light or shutter. It can be set to either `manual` or `auto` , the latter means it follows any schedule set.

More information on using all the services available to this integration can be found [here](https://github.com/asantaga/wiserHomeAssistantPlatform/blob/master/docs/services.md)
More information on using all the services available to this integration can be found [here](https://github.com/asantaga/wiserHomeAssistantPlatform/blob/master/docs/services.md)

- **Events & Triggers**
- A wiser_event event name with a type of boosted, started_heating and stopped_heating. See [Events & Triggers](#events--triggers)


- **Lovelace UI Cards**
- Schedule Card to add, edit, delete and rename schedules
Expand Down Expand Up @@ -476,6 +483,61 @@ You can either provide an entity ID to reference the schedule attached to that e
- Lights - use the Light Mode select entity for the light eg. select.lounge_light_mode
- Shutters - use the Shutter Mode select entity for the shutter eg. select.lounge_blinds_mode


## Events & Triggers

The integration provides a wiser_event event name with types of boosted, started_heating, stopped_heating, target_temperature_increased and target_temperature_decreased, passing also the entity (read climate entity/room) that caused the event. This can be used in 1 or 2 ways.

1. As an automation trigger on a specific 'room' device in the automations UI

```yaml
trigger:
- platform: device
device_id: a45b40d19af72fe76bb5f3c195c24737
domain: wiser
entity_id: climate.wiser_kitchen
type: boosted
```

```yaml
trigger:
- platform: device
device_id: a45b40d19af72fe76bb5f3c195c24737
domain: wiser
entity_id: climate.wiser_kitchen
type: started_heating
```

2. As an event listener in an automation to listen to any events of that type, extract the room that caused it in a template and use that to perform an action.

```yaml
alias: Cap Boost Temperature
description: Listens for boost event and caps to max target temp if above that
trigger:
- platform: event
event_type: wiser_event
event_data:
type: boosted
variables:
cap_temp: 23.5
room: "{{trigger.event.data.entity_id}}"
target_temp: "{{state_attr(trigger.event.data.entity_id, 'temperature')}}"
condition:
- condition: template
value_template: |-
{% if target_temp|float > cap_temp %}
True
{% endif %}
action:
- service: climate.set_temperature
data:
temperature: "{{cap_temp}}"
target:
entity_id: "{{room}}"
mode: queued
max: 10
```

## Schedule Card

This is our first venture into creating UI components for Home Assistant. We have done a lot of testing but there maybe some scenarios we haven't thought of that could exhibit unexpected behaviour. Rest assured however, the worst that can happen is a deleted schedule that you will have to recreate.
Expand Down Expand Up @@ -563,6 +625,15 @@ There are two primary branches for this integration, `master` and `dev` . Master

## Change log

- 3.2.2
- Bump api to v0.1.8
- Add list view option to Schedule Card
- Add Show ID option to schedule card standard view
- Fixed - Update status attribute does not show when failed
- Fixed - Error if heating actuator has no assigned room - Issue [#321](https://github.com/asantaga/wiserHomeAssistantPlatform/issues/321)
- Added events for room started/stopped heating, target temperature increased/decreased and boosted
- Added device_triggers for events

- 3.2.1
- Bump api to v0.1.7 to fix error with UFH controller - issue [#318](https://github.com/asantaga/wiserHomeAssistantPlatform/issues/318)
- Improve setup handling and logging if hub does not respond on initial request - issue [#317](https://github.com/asantaga/wiserHomeAssistantPlatform/issues/317)
Expand Down
31 changes: 9 additions & 22 deletions custom_components/wiser/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""
import logging
from .events import fire_events
import voluptuous as vol

from homeassistant.components.climate.const import (
Expand Down Expand Up @@ -141,17 +142,21 @@ async def async_force_update(self):
@callback
def _handle_coordinator_update(self) -> None:
_LOGGER.debug(f"{self.name} updating")
previous_room_values = self._room
self._room = self._data.wiserhub.rooms.get_by_id(self._room_id)
self._schedule = self._room.schedule

self.async_fire_events()
# Vars to support change fired events
self._is_heating = self._room.is_heating

if not self._room.is_boosted:
self._boosted_time = 0
self.async_write_ha_state()

fire_events(
self._hass,
self.entity_id,
previous_room_values,
self._room,
)

@property
def current_temperature(self):
"""Return current temp from data."""
Expand Down Expand Up @@ -374,24 +379,6 @@ def unique_id(self):
f"{self._data.wiserhub.system.name}-WiserRoom-{self._room_id}-{self.name}"
)

def async_fire_events(self):
# Fire event if is_heating status changed
if self._is_heating != self._room.is_heating:
_LOGGER.debug(
f"Firing wiser_room_heating_status_changed event for {self.name}"
)
self._hass.bus.fire(
"wiser_room_heating_status_changed",
{
"entity_id": self.entity_id,
"is_heating": self._room.is_heating,
"is_boosted": self._room.is_boosted,
"scheduled_temperature": self._room.scheduled_target_temperature,
"target_temperature": self._room.current_target_temperature,
"current_temperature": self._room.current_temperature,
},
)

@callback
async def async_boost_heating(
self, time_period: int, temperature_delta=0, temperature=0
Expand Down
2 changes: 1 addition & 1 deletion custom_components/wiser/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
URL_BASE = "/wiser"
WISER_CARD_FILENAMES = ["wiser-schedule-card.js", "wiser-zigbee-card.js"]

VERSION = "3.2.1"
VERSION = "3.2.2"
WISER_PLATFORMS = [
"climate",
"sensor",
Expand Down
12 changes: 7 additions & 5 deletions custom_components/wiser/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,14 @@ async def async_update_data(self) -> WiserData:
self.hass, "wiser_update_received", self.wiserhub.system.name
)
return True
except WiserHubConnectionError as ex:
_LOGGER.error(ex)
except WiserHubAuthenticationError as ex:
_LOGGER.error(ex)
except WiserHubRESTError as ex:
except (
WiserHubConnectionError,
WiserHubAuthenticationError,
WiserHubRESTError,
) as ex:
self.last_update_status = "Failed"
_LOGGER.error(ex)
except Exception as ex:
self.last_update_status = "Failed"
_LOGGER.error(ex)
raise ex
83 changes: 83 additions & 0 deletions custom_components/wiser/device_trigger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"""Provides device automations for Wiser."""
import voluptuous as vol

from homeassistant.components.device_automation import DEVICE_TRIGGER_BASE_SCHEMA
from homeassistant.const import (
CONF_DEVICE_ID,
CONF_DOMAIN,
CONF_ENTITY_ID,
CONF_PLATFORM,
CONF_TYPE,
)
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
from homeassistant.components.homeassistant.triggers import event as event_trigger
from homeassistant.helpers import config_validation as cv, entity_registry
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
from homeassistant.helpers.typing import ConfigType

from .const import DOMAIN
from .events import WISER_EVENTS, WISER_EVENT

DEVICE = "device"
SUPPORTED_DOMAINS = set(event[CONF_DOMAIN] for event in WISER_EVENTS)

TRIGGER_TYPES = set(event[CONF_TYPE] for event in WISER_EVENTS)

TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend(
{
vol.Required(CONF_ENTITY_ID): cv.entity_id,
vol.Required(CONF_TYPE): vol.In(TRIGGER_TYPES),
}
)


async def async_get_triggers(
hass: HomeAssistant, device_id: str
) -> list[dict[str, str]]:
"""List device triggers for Climate devices."""
registry = entity_registry.async_get(hass)

for entry in entity_registry.async_entries_for_device(registry, device_id):
if entry.domain not in SUPPORTED_DOMAINS:
continue

trigger_types = set(
[
event_type[CONF_TYPE]
for event_type in WISER_EVENTS
if event_type[CONF_DOMAIN] == entry.domain
]
)

return [
{
CONF_PLATFORM: DEVICE,
CONF_DEVICE_ID: device_id,
CONF_DOMAIN: DOMAIN,
CONF_ENTITY_ID: entry.entity_id,
CONF_TYPE: trigger_type,
}
for trigger_type in trigger_types
]


async def async_attach_trigger(
hass: HomeAssistant,
config: ConfigType,
action: TriggerActionType,
trigger_info: TriggerInfo,
) -> CALLBACK_TYPE:
"""Attach a trigger."""
event_config = event_trigger.TRIGGER_SCHEMA(
{
event_trigger.CONF_PLATFORM: "event",
event_trigger.CONF_EVENT_TYPE: WISER_EVENT,
event_trigger.CONF_EVENT_DATA: {
CONF_ENTITY_ID: config[CONF_ENTITY_ID],
CONF_TYPE: config[CONF_TYPE],
},
}
)
return await event_trigger.async_attach_trigger(
hass, event_config, action, trigger_info, platform_type="device"
)
Loading

0 comments on commit 6549411

Please sign in to comment.