Skip to content
Merged
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
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ homeassistant/components/pi_hole/* @fabaff @johnluetke @shenxn
homeassistant/components/pilight/* @trekky12
homeassistant/components/plaato/* @JohNan
homeassistant/components/plex/* @jjlawren
homeassistant/components/plugwise/* @CoMPaTech @bouwew
homeassistant/components/plugwise/* @CoMPaTech @bouwew @brefra
homeassistant/components/plum_lightpad/* @ColinHarrington @prystupa
homeassistant/components/point/* @fredrike
homeassistant/components/poolsense/* @haemishkyd
Expand Down
29 changes: 6 additions & 23 deletions homeassistant/components/plugwise/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
"""Plugwise platform for Home Assistant Core."""
import asyncio

import voluptuous as vol

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST
from homeassistant.core import HomeAssistant

from .const import ALL_PLATFORMS, DOMAIN, UNDO_UPDATE_LISTENER
from .gateway import async_setup_entry_gw

CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.Schema({})}, extra=vol.ALLOW_EXTRA)
from .gateway import async_setup_entry_gw, async_unload_entry_gw


async def async_setup(hass: HomeAssistant, config: dict):
Expand All @@ -27,19 +21,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:


async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Unload a config entry."""
unload_ok = all(
await asyncio.gather(
*[
hass.config_entries.async_forward_entry_unload(entry, component)
for component in ALL_PLATFORMS
]
)
)

hass.data[DOMAIN][entry.entry_id][UNDO_UPDATE_LISTENER]()

if unload_ok:
hass.data[DOMAIN].pop(entry.entry_id)

return unload_ok
"""Unload the Plugwise components."""
if entry.data.get(CONF_HOST):
return await async_unload_entry_gw(hass, entry)
# PLACEHOLDER USB entry setup
return False
10 changes: 5 additions & 5 deletions homeassistant/components/plugwise/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging

from Plugwise_Smile.Smile import Smile
from plugwise.exceptions import PlugwiseException

from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate.const import (
Expand Down Expand Up @@ -192,7 +192,7 @@ async def async_set_temperature(self, **kwargs):
await self._api.set_temperature(self._loc_id, temperature)
self._setpoint = temperature
self.async_write_ha_state()
except Smile.PlugwiseError:
except PlugwiseException:
_LOGGER.error("Error while communicating to device")
else:
_LOGGER.error("Invalid temperature requested")
Expand All @@ -205,15 +205,15 @@ async def async_set_hvac_mode(self, hvac_mode):
try:
await self._api.set_temperature(self._loc_id, self._schedule_temp)
self._setpoint = self._schedule_temp
except Smile.PlugwiseError:
except PlugwiseException:
_LOGGER.error("Error while communicating to device")
try:
await self._api.set_schedule_state(
self._loc_id, self._last_active_schema, state
)
self._hvac_mode = hvac_mode
self.async_write_ha_state()
except Smile.PlugwiseError:
except PlugwiseException:
_LOGGER.error("Error while communicating to device")

async def async_set_preset_mode(self, preset_mode):
Expand All @@ -223,7 +223,7 @@ async def async_set_preset_mode(self, preset_mode):
self._preset_mode = preset_mode
self._setpoint = self._presets.get(self._preset_mode, "none")[0]
self.async_write_ha_state()
except Smile.PlugwiseError:
except PlugwiseException:
_LOGGER.error("Error while communicating to device")

@callback
Expand Down
7 changes: 4 additions & 3 deletions homeassistant/components/plugwise/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Config flow for Plugwise integration."""
import logging

from Plugwise_Smile.Smile import Smile
from plugwise.exceptions import InvalidAuthentication, PlugwiseException
from plugwise.smile import Smile
import voluptuous as vol

from homeassistant import config_entries, core, exceptions
Expand Down Expand Up @@ -67,9 +68,9 @@ async def validate_gw_input(hass: core.HomeAssistant, data):

try:
await api.connect()
except Smile.InvalidAuthentication as err:
except InvalidAuthentication as err:
raise InvalidAuth from err
except Smile.PlugwiseError as err:
except PlugwiseException as err:
raise CannotConnect from err

return api
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/plugwise/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
DOMAIN = "plugwise"

SENSOR_PLATFORMS = ["sensor", "switch"]
ALL_PLATFORMS = ["binary_sensor", "climate", "sensor", "switch"]
PLATFORMS_GATEWAY = ["binary_sensor", "climate", "sensor", "switch"]
PW_TYPE = "plugwise_type"
GATEWAY = "gateway"

# Sensor mapping
SENSOR_MAP_DEVICE_CLASS = 2
Expand Down
24 changes: 16 additions & 8 deletions homeassistant/components/plugwise/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
import logging
from typing import Dict

from Plugwise_Smile.Smile import Smile
import async_timeout
from plugwise.exceptions import (
InvalidAuthentication,
PlugwiseException,
XMLDataMissingError,
)
from plugwise.smile import Smile
import voluptuous as vol

from homeassistant.config_entries import ConfigEntry
Expand All @@ -28,13 +33,15 @@
)

from .const import (
ALL_PLATFORMS,
COORDINATOR,
DEFAULT_PORT,
DEFAULT_SCAN_INTERVAL,
DEFAULT_TIMEOUT,
DEFAULT_USERNAME,
DOMAIN,
GATEWAY,
PLATFORMS_GATEWAY,
PW_TYPE,
SENSOR_PLATFORMS,
UNDO_UPDATE_LISTENER,
)
Expand Down Expand Up @@ -64,11 +71,11 @@ async def async_setup_entry_gw(hass: HomeAssistant, entry: ConfigEntry) -> bool:
_LOGGER.error("Unable to connect to Smile")
raise ConfigEntryNotReady

except Smile.InvalidAuthentication:
except InvalidAuthentication:
_LOGGER.error("Invalid username or Smile ID")
return False

except Smile.PlugwiseError as err:
except PlugwiseException as err:
_LOGGER.error("Error while communicating to device %s", api.smile_name)
raise ConfigEntryNotReady from err

Expand All @@ -88,7 +95,7 @@ async def async_update_data():
async with async_timeout.timeout(DEFAULT_TIMEOUT):
await api.full_update_device()
return True
except Smile.XMLDataMissingError as err:
except XMLDataMissingError as err:
raise UpdateFailed("Smile update failed") from err

coordinator = DataUpdateCoordinator(
Expand All @@ -115,6 +122,7 @@ async def async_update_data():
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = {
"api": api,
COORDINATOR: coordinator,
PW_TYPE: GATEWAY,
UNDO_UPDATE_LISTENER: undo_listener,
}

Expand All @@ -130,7 +138,7 @@ async def async_update_data():

single_master_thermostat = api.single_master_thermostat()

platforms = ALL_PLATFORMS
platforms = PLATFORMS_GATEWAY
if single_master_thermostat is None:
platforms = SENSOR_PLATFORMS

Expand All @@ -150,13 +158,13 @@ async def _update_listener(hass: HomeAssistant, entry: ConfigEntry):
)


async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
async def async_unload_entry_gw(hass: HomeAssistant, entry: ConfigEntry):
"""Unload a config entry."""
unload_ok = all(
await asyncio.gather(
*[
hass.config_entries.async_forward_entry_unload(entry, component)
for component in ALL_PLATFORMS
for component in PLATFORMS_GATEWAY
]
)
)
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/plugwise/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"domain": "plugwise",
"name": "Plugwise",
"documentation": "https://www.home-assistant.io/integrations/plugwise",
"requirements": ["Plugwise_Smile==1.6.0"],
"codeowners": ["@CoMPaTech", "@bouwew"],
"requirements": ["plugwise==0.8.3"],
"codeowners": ["@CoMPaTech", "@bouwew", "@brefra"],
"zeroconf": ["_plugwise._tcp.local."],
"config_flow": true
}
16 changes: 11 additions & 5 deletions homeassistant/components/plugwise/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging

from Plugwise_Smile.Smile import Smile
from plugwise.exceptions import PlugwiseException

from homeassistant.components.switch import SwitchEntity
from homeassistant.core import callback
Expand All @@ -14,6 +14,12 @@


async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the Smile switches from a config entry."""
# PLACEHOLDER USB entry setup
return await async_setup_entry_gateway(hass, config_entry, async_add_entities)


async def async_setup_entry_gateway(hass, config_entry, async_add_entities):
"""Set up the Smile switches from a config entry."""
api = hass.data[DOMAIN][config_entry.entry_id]["api"]
coordinator = hass.data[DOMAIN][config_entry.entry_id][COORDINATOR]
Expand All @@ -37,15 +43,15 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
model = "Switch Group"

entities.append(
PwSwitch(
GwSwitch(
api, coordinator, device_properties["name"], dev_id, members, model
)
)

async_add_entities(entities, True)


class PwSwitch(SmileGateway, SwitchEntity):
class GwSwitch(SmileGateway, SwitchEntity):
"""Representation of a Plugwise plug."""

def __init__(self, api, coordinator, name, dev_id, members, model):
Expand Down Expand Up @@ -79,7 +85,7 @@ async def async_turn_on(self, **kwargs):
if state_on:
self._is_on = True
self.async_write_ha_state()
except Smile.PlugwiseError:
except PlugwiseException:
_LOGGER.error("Error while communicating to device")

async def async_turn_off(self, **kwargs):
Expand All @@ -91,7 +97,7 @@ async def async_turn_off(self, **kwargs):
if state_off:
self._is_on = False
self.async_write_ha_state()
except Smile.PlugwiseError:
except PlugwiseException:
_LOGGER.error("Error while communicating to device")

@callback
Expand Down
6 changes: 3 additions & 3 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ Mastodon.py==1.5.1
# homeassistant.components.orangepi_gpio
OPi.GPIO==0.4.0

# homeassistant.components.plugwise
Plugwise_Smile==1.6.0

# homeassistant.components.essent
PyEssent==0.14

Expand Down Expand Up @@ -1139,6 +1136,9 @@ plexauth==0.0.6
# homeassistant.components.plex
plexwebsocket==0.0.12

# homeassistant.components.plugwise
plugwise==0.8.3

# homeassistant.components.plum_lightpad
plumlightpad==0.0.11

Expand Down
6 changes: 3 additions & 3 deletions requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
# homeassistant.components.homekit
HAP-python==3.0.0

# homeassistant.components.plugwise
Plugwise_Smile==1.6.0

# homeassistant.components.flick_electric
PyFlick==0.0.2

Expand Down Expand Up @@ -562,6 +559,9 @@ plexauth==0.0.6
# homeassistant.components.plex
plexwebsocket==0.0.12

# homeassistant.components.plugwise
plugwise==0.8.3

# homeassistant.components.plum_lightpad
plumlightpad==0.0.11

Expand Down
2 changes: 1 addition & 1 deletion tests/components/plugwise/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Common initialisation for the Plugwise integration."""

from homeassistant.components.plugwise import DOMAIN
from homeassistant.components.plugwise.const import DOMAIN
from homeassistant.core import HomeAssistant

from tests.common import MockConfigEntry
Expand Down
Loading