Skip to content

Commit f904075

Browse files
authored
Merge pull request #69 from plugwise/up110
Combined, non-breaking upstream review and 110 compliancy
2 parents 499e4e2 + c549195 commit f904075

File tree

7 files changed

+27
-59
lines changed

7 files changed

+27
-59
lines changed

custom_components/plugwise-beta/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ async def async_setup_entry(hass, entry):
4646
_LOGGER.error("Unable to connect to Smile: %s",api.smile_status)
4747
raise ConfigEntryNotReady
4848

49+
except Smile.InvalidAuthentication:
50+
_LOGGER.error("Invalid Smile ID")
51+
return False
52+
4953
except Smile.PlugwiseError:
5054
_LOGGER.error("Error while communicating to device")
5155
raise ConfigEntryNotReady
@@ -144,6 +148,12 @@ def __init__(self, api, coordinator):
144148
"""Initialise the sensor."""
145149
self._api = api
146150
self._coordinator = coordinator
151+
self._unique_id = None
152+
153+
@property
154+
def unique_id(self):
155+
"""Return a unique ID."""
156+
return self._unique_id
147157

148158
@property
149159
def should_poll(self):

custom_components/plugwise-beta/binary_sensor.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from homeassistant.components.binary_sensor import (
77
DEVICE_CLASS_OPENING,
8-
BinarySensorDevice,
8+
BinarySensorEntity,
99
)
1010
from homeassistant.const import STATE_OFF, STATE_ON
1111

@@ -63,7 +63,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
6363
async_add_entities(devices, True)
6464

6565

66-
class PwBinarySensor(SmileGateway, BinarySensorDevice):
66+
class PwBinarySensor(SmileGateway, BinarySensorEntity):
6767
"""Representation of a Plugwise binary_sensor."""
6868

6969
def __init__(self, api, coordinator, name, binary_sensor, dev_id, model):
@@ -90,11 +90,6 @@ def __init__(self, api, coordinator, name, binary_sensor, dev_id, model):
9090

9191
self._unique_id = f"bs-{dev_id}-{self._name}-{binary_sensor}"
9292

93-
@property
94-
def unique_id(self):
95-
"""Return a unique ID."""
96-
return self._unique_id
97-
9893
@property
9994
def name(self):
10095
"""Return the name of the thermostat, if any."""

custom_components/plugwise-beta/climate.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import Dict
55
from Plugwise_Smile.Smile import Smile
66

7-
from homeassistant.components.climate import ClimateDevice
7+
from homeassistant.components.climate import ClimateEntity
88
from homeassistant.components.climate.const import (
99
CURRENT_HVAC_COOL,
1010
CURRENT_HVAC_HEAT,
@@ -73,8 +73,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
7373

7474
async_add_entities(devices, True)
7575

76-
77-
class PwThermostat(SmileGateway, ClimateDevice):
76+
class PwThermostat(SmileGateway, ClimateEntity):
7877
"""Representation of an Plugwise thermostat."""
7978

8079
def __init__(self, api, coordinator, name, dev_id, loc_id, model, min_temp, max_temp):
@@ -109,14 +108,6 @@ def __init__(self, api, coordinator, name, dev_id, loc_id, model, min_temp, max_
109108
self._hvac_mode = None
110109
self._single_thermostat = self._api.single_master_thermostat()
111110
self._unique_id = f"cl-{dev_id}-{self._name}"
112-
113-
114-
115-
@property
116-
def unique_id(self):
117-
"""Return a unique ID."""
118-
return self._unique_id
119-
120111

121112
@property
122113
def hvac_action(self):
@@ -141,7 +132,7 @@ def name(self):
141132
def device_info(self) -> Dict[str, any]:
142133
"""Return the device information."""
143134

144-
via_device = self._api.gateway_id
135+
via_device = (DOMAIN, self._api.gateway_id)
145136
if self._dev_id is via_device:
146137
via_device = None
147138

custom_components/plugwise-beta/config_flow.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,15 @@
55
import voluptuous as vol
66

77
from homeassistant import config_entries, core, exceptions
8+
from homeassistant.const import CONF_HOST, CONF_PASSWORD
89
from homeassistant.helpers.aiohttp_client import async_get_clientsession
910
from Plugwise_Smile.Smile import Smile
1011

1112
from .const import DOMAIN # pylint:disable=unused-import
1213

1314
_LOGGER = logging.getLogger(__name__)
1415

15-
16-
def _get_config_schema(input_dict: Dict[str, Any] = None) -> vol.Schema:
17-
"""
18-
Return schema defaults for init step based on user input/config dict.
19-
20-
Retain info already provided for future form views by setting them as defaults in schema.
21-
"""
22-
if input_dict is None:
23-
input_dict = {}
24-
25-
return vol.Schema({vol.Required("host"): str, vol.Required("password"): str})
26-
16+
DATA_SCHEMA = vol.Schema({vol.Required(CONF_HOST): str, vol.Required(CONF_PASSWORD): str})
2717

2818
async def validate_input(hass: core.HomeAssistant, data):
2919
"""
@@ -36,7 +26,11 @@ async def validate_input(hass: core.HomeAssistant, data):
3626
host=data["host"], password=data["password"], timeout=30, websession=websession
3727
)
3828

39-
if not await api.connect():
29+
try:
30+
await api.connect()
31+
except Smile.InvalidAuthentication:
32+
raise InvalidAuth
33+
except Smile.PlugwiseError:
4034
raise CannotConnect
4135

4236
return {"title": api.smile_name}
@@ -48,14 +42,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
4842
VERSION = 1
4943
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL
5044

51-
def __init__(self) -> None:
52-
"""Initialize config flow."""
53-
self._user_schema = None
54-
5545
async def async_step_user(self, user_input=None):
5646
"""Handle the initial step."""
5747
errors = {}
58-
self._user_schema = _get_config_schema(user_input)
5948
if user_input is not None:
6049

6150
try:
@@ -71,7 +60,7 @@ async def async_step_user(self, user_input=None):
7160
errors["base"] = "unknown"
7261

7362
return self.async_show_form(
74-
step_id="user", data_schema=self._user_schema, errors=errors
63+
step_id="user", data_schema=DATA_SCHEMA, errors=errors
7564
)
7665

7766

custom_components/plugwise-beta/sensor.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,6 @@ def __init__(self, api, coordinator, name, dev_id, sensor, sensor_type):
278278

279279
self._unique_id = f"cl-{dev_id}-{self._name}-{sensor}"
280280

281-
282-
@property
283-
def unique_id(self):
284-
"""Return a unique ID."""
285-
return self._unique_id
286-
287281
@property
288282
def device_class(self):
289283
"""Device class of this entity."""
@@ -387,12 +381,6 @@ def __init__(self, api, coordinator, name, dev_id, sensor, sensor_type, model):
387381
if self._dev_id == self._via_id:
388382
self._via_id = None
389383
self._name = f"Smile {self._name}"
390-
391-
392-
@property
393-
def unique_id(self):
394-
"""Return a unique ID."""
395-
return self._unique_id
396384

397385
@property
398386
def name(self):

custom_components/plugwise-beta/switch.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import Dict
55
from Plugwise_Smile.Smile import Smile
66

7-
from homeassistant.components.switch import SwitchDevice
7+
from homeassistant.components.switch import SwitchEntity
88

99
from .const import DOMAIN, SWITCH_ICON
1010

@@ -30,7 +30,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
3030
async_add_entities(devices, True)
3131

3232

33-
class PwSwitch(SmileGateway, SwitchDevice):
33+
class PwSwitch(SmileGateway, SwitchEntity):
3434
"""Representation of a Plugwise plug."""
3535

3636
def __init__(self, api, coordinator, name, dev_id, model):
@@ -44,11 +44,6 @@ def __init__(self, api, coordinator, name, dev_id, model):
4444
self._device_is_on = False
4545
self._unique_id = f"sw-{dev_id}-{self._name}"
4646

47-
@property
48-
def unique_id(self):
49-
"""Return a unique ID."""
50-
return self._unique_id
51-
5247
@property
5348
def is_on(self):
5449
"""Return true if device is on."""
@@ -57,7 +52,7 @@ def is_on(self):
5752
@property
5853
def device_info(self) -> Dict[str, any]:
5954
"""Return the device information."""
60-
via_device = self._api.gateway_id
55+
via_device = (DOMAIN, self._api.gateway_id)
6156
if self._dev_id is via_device:
6257
via_device = None
6358

hacs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Plugwise beta custom component",
33
"domains": ["binary_sensor","climate","sensor","switch"],
4-
"homeassistant": "0.109.0",
4+
"homeassistant": "0.110.0",
55
"render_readme": true
66
}

0 commit comments

Comments
 (0)