mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Use entity class attributes for ambiclimate (#52521)
* Use entity class attributes for ambiclimate * tweak * move some stuff
This commit is contained in:
parent
abc9b01ede
commit
3a2a688170
@ -20,7 +20,7 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass, config) -> bool:
|
||||||
"""Set up Ambiclimate components."""
|
"""Set up Ambiclimate components."""
|
||||||
if DOMAIN not in config:
|
if DOMAIN not in config:
|
||||||
return True
|
return True
|
||||||
@ -34,7 +34,7 @@ async def async_setup(hass, config):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, entry):
|
async def async_setup_entry(hass, entry) -> bool:
|
||||||
"""Set up Ambiclimate from a config entry."""
|
"""Set up Ambiclimate from a config entry."""
|
||||||
hass.async_create_task(
|
hass.async_create_task(
|
||||||
hass.config_entries.async_forward_entry_setup(entry, "climate")
|
hass.config_entries.async_forward_entry_setup(entry, "climate")
|
||||||
|
@ -137,92 +137,33 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||||||
class AmbiclimateEntity(ClimateEntity):
|
class AmbiclimateEntity(ClimateEntity):
|
||||||
"""Representation of a Ambiclimate Thermostat device."""
|
"""Representation of a Ambiclimate Thermostat device."""
|
||||||
|
|
||||||
|
_attr_temperature_unit = TEMP_CELSIUS
|
||||||
|
_attr_target_temperature_step = 1
|
||||||
|
_attr_supported_features = SUPPORT_FLAGS
|
||||||
|
_attr_hvac_modes = [HVAC_MODE_HEAT, HVAC_MODE_OFF]
|
||||||
|
|
||||||
def __init__(self, heater, store):
|
def __init__(self, heater, store):
|
||||||
"""Initialize the thermostat."""
|
"""Initialize the thermostat."""
|
||||||
self._heater = heater
|
self._heater = heater
|
||||||
self._store = store
|
self._store = store
|
||||||
self._data = {}
|
self._attr_unique_id = self._heater.device_id
|
||||||
|
self._attr_name = self._heater.name
|
||||||
@property
|
self._attr_device_info = {
|
||||||
def unique_id(self):
|
|
||||||
"""Return a unique ID."""
|
|
||||||
return self._heater.device_id
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the entity."""
|
|
||||||
return self._heater.name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self):
|
|
||||||
"""Return the device info."""
|
|
||||||
return {
|
|
||||||
"identifiers": {(DOMAIN, self.unique_id)},
|
"identifiers": {(DOMAIN, self.unique_id)},
|
||||||
"name": self.name,
|
"name": self.name,
|
||||||
"manufacturer": "Ambiclimate",
|
"manufacturer": "Ambiclimate",
|
||||||
}
|
}
|
||||||
|
self._attr_min_temp = self._heater.get_min_temp()
|
||||||
|
self._attr_max_temp = self._heater.get_max_temp()
|
||||||
|
|
||||||
@property
|
async def async_set_temperature(self, **kwargs) -> None:
|
||||||
def temperature_unit(self):
|
|
||||||
"""Return the unit of measurement which this thermostat uses."""
|
|
||||||
return TEMP_CELSIUS
|
|
||||||
|
|
||||||
@property
|
|
||||||
def target_temperature(self):
|
|
||||||
"""Return the target temperature."""
|
|
||||||
return self._data.get("target_temperature")
|
|
||||||
|
|
||||||
@property
|
|
||||||
def target_temperature_step(self):
|
|
||||||
"""Return the supported step of target temperature."""
|
|
||||||
return 1
|
|
||||||
|
|
||||||
@property
|
|
||||||
def current_temperature(self):
|
|
||||||
"""Return the current temperature."""
|
|
||||||
return self._data.get("temperature")
|
|
||||||
|
|
||||||
@property
|
|
||||||
def current_humidity(self):
|
|
||||||
"""Return the current humidity."""
|
|
||||||
return self._data.get("humidity")
|
|
||||||
|
|
||||||
@property
|
|
||||||
def min_temp(self):
|
|
||||||
"""Return the minimum temperature."""
|
|
||||||
return self._heater.get_min_temp()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def max_temp(self):
|
|
||||||
"""Return the maximum temperature."""
|
|
||||||
return self._heater.get_max_temp()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def supported_features(self):
|
|
||||||
"""Return the list of supported features."""
|
|
||||||
return SUPPORT_FLAGS
|
|
||||||
|
|
||||||
@property
|
|
||||||
def hvac_modes(self):
|
|
||||||
"""Return the list of available hvac operation modes."""
|
|
||||||
return [HVAC_MODE_HEAT, HVAC_MODE_OFF]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def hvac_mode(self):
|
|
||||||
"""Return current operation."""
|
|
||||||
if self._data.get("power", "").lower() == "on":
|
|
||||||
return HVAC_MODE_HEAT
|
|
||||||
|
|
||||||
return HVAC_MODE_OFF
|
|
||||||
|
|
||||||
async def async_set_temperature(self, **kwargs):
|
|
||||||
"""Set new target temperature."""
|
"""Set new target temperature."""
|
||||||
temperature = kwargs.get(ATTR_TEMPERATURE)
|
temperature = kwargs.get(ATTR_TEMPERATURE)
|
||||||
if temperature is None:
|
if temperature is None:
|
||||||
return
|
return
|
||||||
await self._heater.set_target_temperature(temperature)
|
await self._heater.set_target_temperature(temperature)
|
||||||
|
|
||||||
async def async_set_hvac_mode(self, hvac_mode):
|
async def async_set_hvac_mode(self, hvac_mode) -> None:
|
||||||
"""Set new target hvac mode."""
|
"""Set new target hvac mode."""
|
||||||
if hvac_mode == HVAC_MODE_HEAT:
|
if hvac_mode == HVAC_MODE_HEAT:
|
||||||
await self._heater.turn_on()
|
await self._heater.turn_on()
|
||||||
@ -230,7 +171,7 @@ class AmbiclimateEntity(ClimateEntity):
|
|||||||
if hvac_mode == HVAC_MODE_OFF:
|
if hvac_mode == HVAC_MODE_OFF:
|
||||||
await self._heater.turn_off()
|
await self._heater.turn_off()
|
||||||
|
|
||||||
async def async_update(self):
|
async def async_update(self) -> None:
|
||||||
"""Retrieve latest state."""
|
"""Retrieve latest state."""
|
||||||
try:
|
try:
|
||||||
token_info = await self._heater.control.refresh_access_token()
|
token_info = await self._heater.control.refresh_access_token()
|
||||||
@ -241,4 +182,10 @@ class AmbiclimateEntity(ClimateEntity):
|
|||||||
if token_info:
|
if token_info:
|
||||||
await self._store.async_save(token_info)
|
await self._store.async_save(token_info)
|
||||||
|
|
||||||
self._data = await self._heater.update_device()
|
data = await self._heater.update_device()
|
||||||
|
self._attr_target_temperature = data.get("target_temperature")
|
||||||
|
self._attr_current_temperature = data.get("temperature")
|
||||||
|
self._attr_current_humidity = data.get("humidity")
|
||||||
|
self._attr_hvac_mode = (
|
||||||
|
HVAC_MODE_HEAT if data.get("power", "").lower() == "on" else HVAC_MODE_OFF
|
||||||
|
)
|
||||||
|
@ -139,7 +139,7 @@ class AmbiclimateAuthCallbackView(HomeAssistantView):
|
|||||||
url = AUTH_CALLBACK_PATH
|
url = AUTH_CALLBACK_PATH
|
||||||
name = AUTH_CALLBACK_NAME
|
name = AUTH_CALLBACK_NAME
|
||||||
|
|
||||||
async def get(self, request):
|
async def get(self, request) -> str:
|
||||||
"""Receive authorization token."""
|
"""Receive authorization token."""
|
||||||
code = request.query.get("code")
|
code = request.query.get("code")
|
||||||
if code is None:
|
if code is None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user