Skip to content
1 change: 0 additions & 1 deletion homeassistant/components/comfoconnect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ class ComfoConnectBridge:

def __init__(self, hass, bridge, name, token, friendly_name, pin):
"""Initialize the ComfoConnect bridge."""
self.data = {}
self.name = name
self.hass = hass
self.unique_id = bridge.uuid.hex()
Expand Down
56 changes: 19 additions & 37 deletions homeassistant/components/comfoconnect/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import logging
import math
from typing import Any

from pycomfoconnect import (
CMD_FAN_MODE_AWAY,
Expand Down Expand Up @@ -44,12 +45,18 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
class ComfoConnectFan(FanEntity):
"""Representation of the ComfoConnect fan platform."""

_attr_icon = "mdi:air-conditioner"
_attr_should_poll = False
_attr_supported_features = SUPPORT_SET_SPEED
Comment thread
michaelarnauts marked this conversation as resolved.
Outdated
current_speed = None

def __init__(self, name, ccb: ComfoConnectBridge) -> None:
"""Initialize the ComfoConnect fan."""
self._ccb = ccb
self._name = name
self._attr_name = name
self._attr_unique_id = ccb.unique_id

async def async_added_to_hass(self):
async def async_added_to_hass(self) -> None:
"""Register for sensor updates."""
_LOGGER.debug("Registering for fan speed")
self.async_on_remove(
Expand All @@ -68,58 +75,36 @@ def _handle_update(self, value):
_LOGGER.debug(
"Handle update for fan speed (%d): %s", SENSOR_FAN_SPEED_MODE, value
)
self._ccb.data[SENSOR_FAN_SPEED_MODE] = value
self.current_speed = value
self.schedule_update_ha_state()

@property
def should_poll(self) -> bool:
"""Do not poll."""
return False

@property
def unique_id(self):
"""Return a unique_id for this entity."""
return self._ccb.unique_id

@property
def name(self):
"""Return the name of the fan."""
return self._name

@property
def icon(self):
"""Return the icon to use in the frontend."""
return "mdi:air-conditioner"

@property
def supported_features(self) -> int:
"""Flag supported features."""
return SUPPORT_SET_SPEED

@property
def percentage(self) -> int | None:
"""Return the current speed percentage."""
speed = self._ccb.data.get(SENSOR_FAN_SPEED_MODE)
if speed is None:
if self.current_speed is None:
return None
return ranged_value_to_percentage(SPEED_RANGE, speed)
return ranged_value_to_percentage(SPEED_RANGE, self.current_speed)

@property
def speed_count(self) -> int:
"""Return the number of speeds the fan supports."""
return int_states_in_range(SPEED_RANGE)

def turn_on(
self, speed: str = None, percentage=None, preset_mode=None, **kwargs
self,
speed: str | None = None,
percentage: int | None = None,
preset_mode: str | None = None,
**kwargs,
) -> None:
"""Turn on the fan."""
self.set_percentage(percentage)

def turn_off(self, **kwargs) -> None:
def turn_off(self, **kwargs: Any) -> None:
"""Turn off the fan (to away)."""
self.set_percentage(0)

def set_percentage(self, percentage: int):
def set_percentage(self, percentage: int | None) -> None:
Comment thread
michaelarnauts marked this conversation as resolved.
Outdated
"""Set fan speed percentage."""
_LOGGER.debug("Changing fan speed percentage to %s", percentage)

Expand All @@ -132,6 +117,3 @@ def set_percentage(self, percentage: int):
cmd = CMD_MAPPING[speed]

self._ccb.comfoconnect.cmd_rmi_request(cmd)

# Update current mode
self.schedule_update_ha_state()
Loading