This repository was archived by the owner on Jul 25, 2022. It is now read-only.
forked from bdraco/baf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclimate.py
More file actions
60 lines (49 loc) · 2.07 KB
/
climate.py
File metadata and controls
60 lines (49 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""Support for Big Ass Fans auto comfort."""
from __future__ import annotations
from typing import Any
from homeassistant import config_entries
from homeassistant.components.climate import (
ClimateEntity,
ClimateEntityFeature,
HVACAction,
HVACMode,
)
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import DOMAIN
from .entity import BAFEntity
from .models import BAFData
async def async_setup_entry(
hass: HomeAssistant,
entry: config_entries.ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up BAF fan switches."""
data: BAFData = hass.data[DOMAIN][entry.entry_id]
device = data.device
if not device.has_fan:
return
async_add_entities([BAFAutoComfort(device, f"{device.name} Auto Comfort")])
class BAFAutoComfort(BAFEntity, ClimateEntity):
"""BAF climate auto comfort."""
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
_attr_temperature_unit = TEMP_CELSIUS
_attr_hvac_modes = [HVACMode.OFF, HVACMode.FAN_ONLY]
@callback
def _async_update_attrs(self) -> None:
"""Update attrs from device."""
device = self._device
auto_on = device.auto_comfort_enable
self._attr_hvac_mode = HVACMode.FAN_ONLY if auto_on else HVACMode.OFF
self._attr_hvac_action = HVACAction.FAN if device.speed else HVACAction.OFF
self._attr_target_temperature = device.comfort_ideal_temperature
self._attr_current_temperature = device.temperature
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set the HVAC mode."""
self._device.auto_comfort_enable = hvac_mode == HVACMode.FAN_ONLY
async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set the target temperature."""
if not self._device.auto_comfort_enable:
self._device.auto_comfort_enable = True
self._device.comfort_ideal_temperature = kwargs[ATTR_TEMPERATURE]