Skip to content

Commit

Permalink
Merge pull request #473 from asantaga/dev
Browse files Browse the repository at this point in the history
v3.4.7
  • Loading branch information
msp1974 committed May 4, 2024
2 parents 8277c74 + 3e97507 commit e898cff
Show file tree
Hide file tree
Showing 10 changed files with 318 additions and 206 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Wiser Home Assistant Integration v3.4.6
# Wiser Home Assistant Integration v3.4.7

[![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 @@ -25,6 +25,15 @@ For more information checkout the AMAZING community thread available on

## Change log

- v3.4.7
- Bump api to v1.5.14 to improve handling of hub connection errors
- Fix - improve handling of hub update failures - [#434](https://github.com/asantaga/wiserHomeAssistantPlatform/issues/434)
- Fix - set entity values to unknown if not provided in the hub update - [#471](https://github.com/asantaga/wiserHomeAssistantPlatform/issues/471)
- Fix - removed use of async_add_job - [#463](https://github.com/asantaga/wiserHomeAssistantPlatform/issues/463)
- Fix - add color modes to lights - [#458](https://github.com/asantaga/wiserHomeAssistantPlatform/issues/458)
- Fix - use default boost temp with presets - [#467](https://github.com/asantaga/wiserHomeAssistantPlatform/issues/467)
- Add ability to unassign a schedule via the assign schedule service - [#470](https://github.com/asantaga/wiserHomeAssistantPlatform/issues/470)

- v3.4.6
- Bump api to v1.5.13 to improve retry handling to include hub conneciton error
- Prevent entities going unavailable if hub update failed
Expand Down
25 changes: 12 additions & 13 deletions custom_components/wiser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
Drayton Wiser Compoment for Wiser System.
"""Drayton Wiser Compoment for Wiser System.
https://github.com/asantaga/wiserHomeAssistantPlatform
msparker@sky.com
"""

import asyncio
import logging

Expand All @@ -12,12 +12,6 @@
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC

from .coordinator import WiserUpdateCoordinator
from .frontend import WiserCardRegistration
from .helpers import get_device_name, get_identifier, get_instance_count
from .services import async_setup_services
from .websockets import async_register_websockets

from .const import (
DATA,
DOMAIN,
Expand All @@ -26,6 +20,11 @@
WISER_PLATFORMS,
WISER_SERVICES,
)
from .coordinator import WiserUpdateCoordinator
from .frontend import WiserCardRegistration
from .helpers import get_device_name, get_identifier, get_instance_count
from .services import async_setup_services
from .websockets import async_register_websockets

_LOGGER = logging.getLogger(__name__)

Expand All @@ -51,7 +50,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry):

# Setup platforms
for platform in WISER_PLATFORMS:
hass.async_add_job(
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(config_entry, platform)
)

Expand All @@ -69,7 +68,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry):
await cards.async_register()

_LOGGER.info(
f"Wiser Component Setup Completed ({coordinator.wiserhub.system.name})"
"Wiser Component Setup Completed (%s)", coordinator.wiserhub.system.name
)
return True

Expand Down Expand Up @@ -99,7 +98,7 @@ async def _async_update_listener(hass: HomeAssistant, config_entry):
async def async_remove_config_entry_device(
hass: HomeAssistant, config_entry, device_entry
) -> bool:
"""Delete device if not entities"""
"""Delete device if not entities."""
if device_entry.model == "Controller":
_LOGGER.error(
"You cannot delete the Wiser Controller using device delete. Please remove the integration instead"
Expand All @@ -109,7 +108,7 @@ async def async_remove_config_entry_device(


async def async_unload_entry(hass: HomeAssistant, config_entry):
"""Unload a config entry"""
"""Unload a config entry."""

if get_instance_count(hass) == 0:
# Unload lovelace module resource if only instance
Expand All @@ -119,7 +118,7 @@ async def async_unload_entry(hass: HomeAssistant, config_entry):

# Deregister services if only instance
_LOGGER.debug("Unregister Wiser services")
for k, service in WISER_SERVICES.items():
for service in WISER_SERVICES.values():
hass.services.async_remove(DOMAIN, service)

_LOGGER.debug("Unload Wiser integration platforms")
Expand Down
56 changes: 44 additions & 12 deletions custom_components/wiser/button.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
"""Button entities."""

import asyncio
import logging

from homeassistant.components.button import ButtonEntity
from homeassistant.core import HomeAssistant
from homeassistant.util import dt as dt_util
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.util import dt as dt_util

from .helpers import get_device_name, get_unique_id, get_identifier, hub_error_handler

from .const import (
DATA,
DOMAIN,
MANUFACTURER,
)
from .const import DATA, DOMAIN, MANUFACTURER
from .helpers import get_device_name, get_identifier, get_unique_id, hub_error_handler

_LOGGER = logging.getLogger(__name__)

Expand All @@ -39,22 +36,26 @@ async def async_setup_entry(hass: HomeAssistant, config_entry, async_add_entitie

if data.wiserhub.moments:
_LOGGER.debug("Setting up Moments buttons")
for moment in data.wiserhub.moments.all:
wiser_buttons.append(WiserMomentsButton(data, moment.id))
wiser_buttons = [
WiserMomentsButton(data, moment.id) for moment in data.wiserhub.moments.all
]

async_add_entities(wiser_buttons, True)


class WiserButton(CoordinatorEntity, ButtonEntity):
"""Class to handle a button entity."""

def __init__(self, coordinator, name="Button") -> None:
"""Initialize the sensor."""
super().__init__(coordinator)
self._data = coordinator
self._name = name
_LOGGER.debug(f"{self._data.wiserhub.system.name} {self.name} initalise")
_LOGGER.debug("%s %s initialise", self._data.wiserhub.system.name, self.name)

async def async_force_update(self, delay: int = 0):
_LOGGER.debug(f"Hub update initiated by {self.name}")
"""Force an update from the hub."""
_LOGGER.debug("Hub update initiated by %s", self.name)
if delay:
asyncio.sleep(delay)
state = await self.async_get_last_state()
Expand All @@ -71,6 +72,7 @@ def unique_id(self):

@property
def name(self):
"""Return entity name."""
return get_device_name(self._data, 0, self._name)

@property
Expand All @@ -87,92 +89,122 @@ def device_info(self):


class WiserBoostAllHeatingButton(WiserButton):
"""Class to handle Heating button."""

def __init__(self, data) -> None:
"""Init."""
super().__init__(data, "Boost All Heating")

@hub_error_handler
async def async_press(self):
"""Handle button press."""
boost_time = self._data.boost_time
boost_temp = self._data.boost_temp
await self._data.wiserhub.system.boost_all_rooms(boost_temp, boost_time)
await self.async_force_update()

@property
def icon(self):
"""Return icon."""
return "mdi:fire"


class WiserCancelHeatingOverridesButton(WiserButton):
"""Class to handle heating overrides button."""

def __init__(self, data) -> None:
"""Init."""
super().__init__(data, "Cancel All Heating Overrides")

@hub_error_handler
async def async_press(self):
"""Handle button press."""
await self._data.wiserhub.system.cancel_all_overrides()
await self.async_force_update()

@property
def icon(self):
"""Return icon."""
return "mdi:fire-off"


class WiserBoostHotWaterButton(WiserButton):
"""Class to handle hot water button."""

def __init__(self, data) -> None:
"""Init."""
super().__init__(data, "Boost Hot Water")

@hub_error_handler
async def async_press(self):
"""Handle button press."""
boost_time = self._data.hw_boost_time
await self._data.wiserhub.hotwater.boost(boost_time)
await self.async_force_update()

@property
def icon(self):
"""Return icon."""
return "mdi:water-plus"


class WiserCancelHotWaterOverridesButton(WiserButton):
"""Class to handle cancel hot water overrides button."""

def __init__(self, data) -> None:
"""Init."""
super().__init__(data, "Cancel Hot Water Overrides")

@hub_error_handler
async def async_press(self):
"""Handle button press."""
await self._data.wiserhub.hotwater.cancel_overrides()
await self.async_force_update()

@property
def icon(self):
"""Return icon."""
return "mdi:water-off"


class WiserOverrideHotWaterButton(WiserButton):
"""Class to handle hot water override button."""

def __init__(self, data) -> None:
"""Init."""
super().__init__(data, "Toggle Hot Water")

@hub_error_handler
async def async_press(self):
"""Handle button press."""
await self._data.wiserhub.hotwater.override_state(
"Off" if self._data.wiserhub.hotwater.current_state == "On" else "On"
)
await self.async_force_update()

@property
def icon(self):
"""Return icon."""
return "mdi:water-boiler"


class WiserMomentsButton(WiserButton):
"""Class to handle moments button."""

def __init__(self, data, moment_id) -> None:
"""Init."""
self._moment_id = moment_id
super().__init__(
data, f"Moments {data.wiserhub.moments.get_by_id(moment_id).name}"
)

@hub_error_handler
async def async_press(self):
"""Handle button press."""
await self._data.wiserhub.moments.get_by_id(self._moment_id).activate()
await self.async_force_update()

@property
def icon(self):
"""Return icon."""
return "mdi:home-thermometer"
Loading

0 comments on commit e898cff

Please sign in to comment.