Skip to content

Commit

Permalink
Some fixes since latest HA breaking changes (#6)
Browse files Browse the repository at this point in the history
* fix: support for ClimateEntityFeature

* Update hacs.json

* Update manifest.json

* Update hacs.json

* Update manifest.json

* Update climate.py

* Update climate.py

* fix

* fix: preset_mode vs preset_modes

* bump

* Small adjustments

* Update custom_components/qubino_wire_pilot/manifest.json

---------

Co-authored-by: Paul Bottein <[email protected]>
  • Loading branch information
dx44 and piitaya authored Nov 15, 2023
1 parent 32af168 commit aa85b62
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 42 deletions.
67 changes: 32 additions & 35 deletions custom_components/qubino_wire_pilot/climate.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
"""Platform for Roth Touchline heat pump controller."""
"""Platform for Qubino Wire Pilot."""
import logging

from typing import List

import voluptuous as vol

from homeassistant.components.climate import PLATFORM_SCHEMA
try:
from homeassistant.components.climate import ClimateEntity
except ImportError:
from homeassistant.components.climate import ClimateDevice as ClimateEntity

from homeassistant.components.climate import (
PLATFORM_SCHEMA,
ClimateEntity,
ClimateEntityFeature
)
from homeassistant.components.climate.const import (
SUPPORT_PRESET_MODE,
HVAC_MODE_OFF,
HVAC_MODE_HEAT,
PRESET_ECO,
PRESET_COMFORT,
PRESET_AWAY,
PRESET_NONE,
HVACMode
)
from homeassistant.const import (
TEMP_CELSIUS,
Expand All @@ -27,7 +24,8 @@
EVENT_HOMEASSISTANT_START,
ATTR_ENTITY_ID,
STATE_UNKNOWN,
STATE_UNAVAILABLE,
STATE_OFF,
STATE_UNAVAILABLE
)
from homeassistant.core import callback

Expand Down Expand Up @@ -65,8 +63,6 @@
}
)

SUPPORT_FLAGS = SUPPORT_PRESET_MODE


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the wire pilot climate platform."""
Expand Down Expand Up @@ -123,26 +119,27 @@ def _async_startup(event):
EVENT_HOMEASSISTANT_START, _async_startup)

@property
def supported_features(self):
def supported_features(self) -> ClimateEntityFeature:
"""Return the list of supported features."""
return SUPPORT_FLAGS
return ClimateEntityFeature.PRESET_MODE

def update(self):
"""Update unit attributes."""

# Temperature
@property
def temperature_unit(self):
def temperature_unit(self) -> str:
"""Return the unit of measurement."""
return TEMP_CELSIUS

@property
def current_temperature(self):
def current_temperature(self) -> float | None:
"""Return the sensor temperature."""
return self._cur_temperature

@property
def heater_value(self):
def heater_value(self) -> int | None:
"""Return entity brightness"""
state = self.hass.states.get(self.heater_entity_id)

if state is None:
Expand All @@ -158,19 +155,19 @@ def heater_value(self):

# Presets
@property
def preset_modes(self):
def preset_modes(self) -> list[str] | None:
"""List of available preset modes."""
if self.additional_modes:
return [PRESET_COMFORT, PRESET_COMFORT_1, PRESET_COMFORT_2, PRESET_ECO, PRESET_AWAY]
return [PRESET_COMFORT, PRESET_COMFORT_1, PRESET_COMFORT_2, PRESET_ECO, PRESET_AWAY, PRESET_NONE]
else:
return [PRESET_COMFORT, PRESET_ECO, PRESET_AWAY]
return [PRESET_COMFORT, PRESET_ECO, PRESET_AWAY, PRESET_NONE]

@property
def preset_mode(self):
def preset_mode(self) -> str | None:
value = self.heater_value

if value is None:
return STATE_UNKNOWN
return None
if value <= VALUE_OFF:
return PRESET_NONE
elif value <= VALUE_FROST:
Expand All @@ -184,7 +181,7 @@ def preset_mode(self):
else:
return PRESET_COMFORT

async def async_set_preset_mode(self, preset_mode):
async def async_set_preset_mode(self, preset_mode: str) -> None:
value = VALUE_OFF

if preset_mode == PRESET_AWAY:
Expand All @@ -202,38 +199,38 @@ async def async_set_preset_mode(self, preset_mode):

# Modes
@property
def hvac_modes(self):
def hvac_modes(self) -> list[HVACMode]:
"""List of available operation modes."""
return [HVAC_MODE_HEAT, HVAC_MODE_OFF]
return [HVACMode.HEAT, HVACMode.OFF]

async def async_set_hvac_mode(self, hvac_mode):
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
value = VALUE_FROST

if hvac_mode == HVAC_MODE_HEAT:
if hvac_mode == HVACMode.HEAT:
value = VALUE_COMFORT
elif hvac_mode == HVAC_MODE_OFF:
elif hvac_mode == HVACMode.OFF:
value = VALUE_OFF

await self._async_set_heater_value(value)

@property
def hvac_mode(self):
def hvac_mode(self) -> HVACMode | str | None:
value = self.heater_value

if value is None:
return STATE_UNKNOWN
return None
if value <= VALUE_OFF:
return HVAC_MODE_OFF
return HVACMode.OFF
else:
return HVAC_MODE_HEAT
return HVACMode.HEAT

@callback
def _async_heater_changed(self, entity_id, old_state, new_state):
def _async_heater_changed(self, entity_id, old_state, new_state) -> None:
if new_state is None:
return
self.async_schedule_update_ha_state()

async def _async_temperature_changed(self, entity_id, old_state, new_state):
async def _async_temperature_changed(self, entity_id, old_state, new_state) -> None:
if new_state is None:
return
self._async_update_temperature(new_state)
Expand Down
8 changes: 4 additions & 4 deletions custom_components/qubino_wire_pilot/manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"domain": "qubino_wire_pilot",
"name": "Qubino wire pilot",
"documentation": "https://github.com/piitaya/home-assitant-qubino_wire_pilot",
"issue_tracker": "https://github.com/piitaya/home-assitant-qubino_wire_pilot/issues",
"documentation": "https://github.com/piitaya/home-assistant-qubino-wire-pilot",
"issue_tracker": "https://github.com/piitaya/home-assistant-qubino-wire-pilot/issues",
"requirements": [],
"dependencies": [],
"version": "2.0.0",
"codeowners": ["@piitaya"]
"version": "2.0.1",
"codeowners": ["@piitaya","@dx44"]
}
5 changes: 2 additions & 3 deletions hacs.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"domains": ["climate"],
"name": "Qubino Wire Pilot",
"render_readme": true,
"homeassistant": "0.96.0"
}
"homeassistant": "2023.1.0"
}

0 comments on commit aa85b62

Please sign in to comment.