Skip to content

Commit 5ca004a

Browse files
authored
Merge pull request #70 from plugwise/up111
Review comments 0.111
2 parents f904075 + f89d0c2 commit 5ca004a

File tree

7 files changed

+64
-41
lines changed

7 files changed

+64
-41
lines changed

custom_components/plugwise-beta/binary_sensor.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,11 @@ def __init__(self, api, coordinator, name, binary_sensor, dev_id, model):
8080
if self._dev_id == self._api.heater_id:
8181
self._name = f"Auxiliary"
8282

83-
bsensorname = binary_sensor.replace("_", " ").title()
84-
self._sensorname = f"{self._name} {bsensorname}"
85-
86-
self._via_id = self._api.gateway_id
8783
if self._dev_id == self._api.gateway_id:
8884
self._name = f"Smile {self._name}"
89-
self._via_id = None
85+
86+
bsensorname = binary_sensor.replace("_", " ").title()
87+
self._sensorname = f"{self._name} {bsensorname}"
9088

9189
self._unique_id = f"bs-{dev_id}-{self._name}-{binary_sensor}"
9290

@@ -110,14 +108,19 @@ def state(self):
110108
@property
111109
def device_info(self) -> Dict[str, any]:
112110
"""Return the device information."""
113-
return {
111+
112+
device_information = {
114113
"identifiers": {(DOMAIN, self._dev_id)},
115114
"name": self._name,
116115
"manufacturer": "Plugwise",
117-
"model": self._model.replace("_", " ").title(),
118-
"via_device": (DOMAIN, self._via_id),
116+
"model": self._model,
119117
}
120118

119+
if self._dev_id != self._api.gateway_id:
120+
device_information["via_device"] = (DOMAIN, self._api.gateway_id)
121+
122+
return device_information
123+
121124
@property
122125
def icon(self):
123126
"""Return the icon to use in the frontend."""

custom_components/plugwise-beta/climate.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@
2323
THERMOSTAT_ICON,
2424
DEFAULT_MIN_TEMP,
2525
DEFAULT_MAX_TEMP,
26+
SCHEDULE_ON,
27+
SCHEDULE_OFF,
2628
)
2729

2830
from . import SmileGateway
2931

30-
HVAC_MODES_1 = [HVAC_MODE_HEAT, HVAC_MODE_AUTO]
31-
HVAC_MODES_2 = [HVAC_MODE_HEAT_COOL, HVAC_MODE_AUTO]
32+
HVAC_MODES_HEAT_ONLY = [HVAC_MODE_HEAT, HVAC_MODE_AUTO]
33+
HVAC_MODES_HEAT_COOL = [HVAC_MODE_HEAT_COOL, HVAC_MODE_AUTO]
3234

3335
SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE
3436

@@ -132,18 +134,18 @@ def name(self):
132134
def device_info(self) -> Dict[str, any]:
133135
"""Return the device information."""
134136

135-
via_device = (DOMAIN, self._api.gateway_id)
136-
if self._dev_id is via_device:
137-
via_device = None
138-
139-
return {
137+
device_information = {
140138
"identifiers": {(DOMAIN, self._dev_id)},
141139
"name": self._name,
142140
"manufacturer": "Plugwise",
143141
"model": self._model.replace("_", " ").title(),
144-
"via_device": via_device,
145142
}
146143

144+
if self._dev_id != self._api.gateway_id:
145+
device_information["via_device"] = (DOMAIN, self._api.gateway_id)
146+
147+
return device_information
148+
147149
@property
148150
def icon(self):
149151
"""Return the icon to use in the frontend."""
@@ -159,8 +161,7 @@ def device_state_attributes(self):
159161
"""Return the device specific state attributes."""
160162
attributes = {}
161163
if self._schema_names:
162-
if len(self._schema_names) > 1:
163-
attributes["available_schemas"] = self._schema_names
164+
attributes["available_schemas"] = self._schema_names
164165
if self._selected_schema:
165166
attributes["selected_schema"] = self._selected_schema
166167
return attributes
@@ -175,8 +176,8 @@ def hvac_modes(self):
175176
"""Return the available hvac modes list."""
176177
if self._heating_state is not None or self._boiler_state is not None:
177178
if self._cooling_state is not None:
178-
return HVAC_MODES_2
179-
return HVAC_MODES_1
179+
return HVAC_MODES_HEAT_COOL
180+
return HVAC_MODES_HEAT_ONLY
180181

181182
@property
182183
def hvac_mode(self):
@@ -234,9 +235,9 @@ async def async_set_temperature(self, **kwargs):
234235
async def async_set_hvac_mode(self, hvac_mode):
235236
"""Set the hvac mode."""
236237
_LOGGER.debug("Set hvac_mode to: %s", hvac_mode)
237-
state = "false"
238+
state = SCHEDULE_OFF
238239
if hvac_mode == HVAC_MODE_AUTO:
239-
state = "true"
240+
state = SCHEDULE_ON
240241
try:
241242
await self._api.set_temperature(self._loc_id, self._schedule_temp)
242243
self._setpoint = self._schedule_temp

custom_components/plugwise-beta/config_flow.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async def validate_input(hass: core.HomeAssistant, data):
3333
except Smile.PlugwiseError:
3434
raise CannotConnect
3535

36-
return {"title": api.smile_name}
36+
return api
3737

3838

3939
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
@@ -45,12 +45,13 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
4545
async def async_step_user(self, user_input=None):
4646
"""Handle the initial step."""
4747
errors = {}
48+
errors = None
4849
if user_input is not None:
4950

5051
try:
51-
info = await validate_input(self.hass, user_input)
52+
api = await validate_input(self.hass, user_input)
5253

53-
return self.async_create_entry(title=info["title"], data=user_input)
54+
return self.async_create_entry(title=api.smile_name, data=user_input)
5455
except CannotConnect:
5556
errors["base"] = "cannot_connect"
5657
except InvalidAuth:
@@ -59,6 +60,12 @@ async def async_step_user(self, user_input=None):
5960
_LOGGER.exception("Unexpected exception")
6061
errors["base"] = "unknown"
6162

63+
if not errors:
64+
await self.async_set_unique_id(api.gateway_id)
65+
self._abort_if_unique_id_configured()
66+
67+
return self.async_create_entry(title=api.smile_name, data=user_input)
68+
6269
return self.async_show_form(
6370
step_id="user", data_schema=DATA_SCHEMA, errors=errors
6471
)

custom_components/plugwise-beta/const.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
CURRENT_HVAC_DHW = "hot_water"
2929
DEVICE_STATE = "device_state"
3030

31+
SCHEDULE_ON = "true"
32+
SCHEDULE_OFF = "false"
33+
3134
# Icons
3235
SWITCH_ICON = "mdi:electric-switch"
3336
THERMOSTAT_ICON = "mdi:thermometer"

custom_components/plugwise-beta/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"domain": "plugwise-beta",
33
"name": "Plugwise Beta for Home Assistant",
44
"documentation": "https://github.com/plugwise/plugwise-beta",
5-
"requirements": ["Plugwise_Smile==0.2.11"],
5+
"requirements": ["Plugwise_Smile==0.2.12"],
66
"dependencies": [],
77
"codeowners": ["@CoMPaTech","@bouwew"],
88
"config_flow": true

custom_components/plugwise-beta/sensor.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ def __init__(self, api, coordinator, name, dev_id, sensor, sensor_type):
251251
self._api = api
252252
self._dev_id = dev_id
253253
if sensor_type is not None:
254+
self._model = sensor_type[0]
254255
self._unit_of_measurement = sensor_type[1]
255256
self._device = sensor_type[2]
256257
self._icon = sensor_type[3]
@@ -271,10 +272,8 @@ def __init__(self, api, coordinator, name, dev_id, sensor, sensor_type):
271272
sensorname = sensor.replace("_", " ").title()
272273
self._sensorname = f"{self._name} {sensorname}"
273274

274-
self._via_id = self._api.gateway_id
275275
if self._dev_id == self._api.gateway_id:
276276
self._name = f"Smile {self._name}"
277-
self._via_id = None
278277

279278
self._unique_id = f"cl-{dev_id}-{self._name}-{sensor}"
280279

@@ -296,13 +295,19 @@ def state(self):
296295
@property
297296
def device_info(self) -> Dict[str, any]:
298297
"""Return the device information."""
299-
return {
298+
299+
device_information = {
300300
"identifiers": {(DOMAIN, self._dev_id)},
301301
"name": self._name,
302302
"manufacturer": "Plugwise",
303-
"via_device": (DOMAIN, self._via_id),
303+
"model": self._model,
304304
}
305305

306+
if self._dev_id != self._api.gateway_id:
307+
device_information["via_device"] = (DOMAIN, self._api.gateway_id)
308+
309+
return device_information
310+
306311
@property
307312
def unit_of_measurement(self):
308313
"""Return the unit of measurement."""
@@ -377,9 +382,7 @@ def __init__(self, api, coordinator, name, dev_id, sensor, sensor_type, model):
377382
sensorname = sensor.replace("_", " ").title()
378383
self._sensorname = f"{name} {sensorname}"
379384

380-
self._via_id = self._api.gateway_id
381-
if self._dev_id == self._via_id:
382-
self._via_id = None
385+
if self._dev_id == self._api.gateway_id:
383386
self._name = f"Smile {self._name}"
384387

385388
@property
@@ -405,14 +408,19 @@ def state(self):
405408
@property
406409
def device_info(self) -> Dict[str, any]:
407410
"""Return the device information."""
408-
return {
411+
412+
device_information = {
409413
"identifiers": {(DOMAIN, self._dev_id)},
410414
"name": self._name,
411415
"manufacturer": "Plugwise",
412-
"model": self._model,
413-
"via_device": (DOMAIN, self._via_id),
416+
"model": self._device,
414417
}
415418

419+
if self._dev_id != self._api.gateway_id:
420+
device_information["via_device"] = (DOMAIN, self._api.gateway_id)
421+
422+
return device_information
423+
416424
@property
417425
def unit_of_measurement(self):
418426
"""Return the unit of measurement of this entity, if any."""

custom_components/plugwise-beta/switch.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,19 @@ def is_on(self):
5252
@property
5353
def device_info(self) -> Dict[str, any]:
5454
"""Return the device information."""
55-
via_device = (DOMAIN, self._api.gateway_id)
56-
if self._dev_id is via_device:
57-
via_device = None
5855

59-
return {
56+
device_information = {
6057
"identifiers": {(DOMAIN, self._dev_id)},
6158
"name": self._name,
6259
"manufacturer": "Plugwise",
6360
"model": self._model,
64-
"via_device": via_device,
6561
}
6662

63+
if self._dev_id != self._api.gateway_id:
64+
device_information["via_device"] = (DOMAIN, self._api.gateway_id)
65+
66+
return device_information
67+
6768
async def turn_on(self, **kwargs):
6869
"""Turn the device on."""
6970
_LOGGER.debug("Turn switch.%s on.", self._name)

0 commit comments

Comments
 (0)