From f52fa3599fe74bdaa1682b8f3825256510478313 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 2 Jun 2022 17:51:27 -1000 Subject: [PATCH] Only create auto comfort entities for BAF devices that support them (#72948) --- homeassistant/components/baf/climate.py | 2 +- homeassistant/components/baf/manifest.json | 2 +- homeassistant/components/baf/number.py | 47 ++++++++++++---------- homeassistant/components/baf/sensor.py | 6 ++- homeassistant/components/baf/switch.py | 7 +++- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 7 files changed, 40 insertions(+), 28 deletions(-) diff --git a/homeassistant/components/baf/climate.py b/homeassistant/components/baf/climate.py index f785d18e06f..d4ed4ac4337 100644 --- a/homeassistant/components/baf/climate.py +++ b/homeassistant/components/baf/climate.py @@ -26,7 +26,7 @@ async def async_setup_entry( ) -> None: """Set up BAF fan auto comfort.""" data: BAFData = hass.data[DOMAIN][entry.entry_id] - if data.device.has_fan: + if data.device.has_fan and data.device.has_auto_comfort: async_add_entities( [BAFAutoComfort(data.device, f"{data.device.name} Auto Comfort")] ) diff --git a/homeassistant/components/baf/manifest.json b/homeassistant/components/baf/manifest.json index 9dfc35685e3..8143c35410e 100644 --- a/homeassistant/components/baf/manifest.json +++ b/homeassistant/components/baf/manifest.json @@ -3,7 +3,7 @@ "name": "Big Ass Fans", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/baf", - "requirements": ["aiobafi6==0.3.0"], + "requirements": ["aiobafi6==0.5.0"], "codeowners": ["@bdraco", "@jfroy"], "iot_class": "local_push", "zeroconf": [ diff --git a/homeassistant/components/baf/number.py b/homeassistant/components/baf/number.py index 84358e79669..32a3ea5e693 100644 --- a/homeassistant/components/baf/number.py +++ b/homeassistant/components/baf/number.py @@ -36,27 +36,7 @@ class BAFNumberDescription(NumberEntityDescription, BAFNumberDescriptionMixin): """Class describing BAF sensor entities.""" -FAN_NUMBER_DESCRIPTIONS = ( - BAFNumberDescription( - key="return_to_auto_timeout", - name="Return to Auto Timeout", - min_value=ONE_MIN_SECS, - max_value=HALF_DAY_SECS, - entity_category=EntityCategory.CONFIG, - unit_of_measurement=TIME_SECONDS, - value_fn=lambda device: cast(Optional[int], device.return_to_auto_timeout), - mode=NumberMode.SLIDER, - ), - BAFNumberDescription( - key="motion_sense_timeout", - name="Motion Sense Timeout", - min_value=ONE_MIN_SECS, - max_value=ONE_DAY_SECS, - entity_category=EntityCategory.CONFIG, - unit_of_measurement=TIME_SECONDS, - value_fn=lambda device: cast(Optional[int], device.motion_sense_timeout), - mode=NumberMode.SLIDER, - ), +AUTO_COMFORT_NUMBER_DESCRIPTIONS = ( BAFNumberDescription( key="comfort_min_speed", name="Auto Comfort Minimum Speed", @@ -86,6 +66,29 @@ FAN_NUMBER_DESCRIPTIONS = ( ), ) +FAN_NUMBER_DESCRIPTIONS = ( + BAFNumberDescription( + key="return_to_auto_timeout", + name="Return to Auto Timeout", + min_value=ONE_MIN_SECS, + max_value=HALF_DAY_SECS, + entity_category=EntityCategory.CONFIG, + unit_of_measurement=TIME_SECONDS, + value_fn=lambda device: cast(Optional[int], device.return_to_auto_timeout), + mode=NumberMode.SLIDER, + ), + BAFNumberDescription( + key="motion_sense_timeout", + name="Motion Sense Timeout", + min_value=ONE_MIN_SECS, + max_value=ONE_DAY_SECS, + entity_category=EntityCategory.CONFIG, + unit_of_measurement=TIME_SECONDS, + value_fn=lambda device: cast(Optional[int], device.motion_sense_timeout), + mode=NumberMode.SLIDER, + ), +) + LIGHT_NUMBER_DESCRIPTIONS = ( BAFNumberDescription( key="light_return_to_auto_timeout", @@ -125,6 +128,8 @@ async def async_setup_entry( descriptions.extend(FAN_NUMBER_DESCRIPTIONS) if device.has_light: descriptions.extend(LIGHT_NUMBER_DESCRIPTIONS) + if device.has_auto_comfort: + descriptions.extend(AUTO_COMFORT_NUMBER_DESCRIPTIONS) async_add_entities(BAFNumber(device, description) for description in descriptions) diff --git a/homeassistant/components/baf/sensor.py b/homeassistant/components/baf/sensor.py index 0f4239962cf..7b93b22fe2f 100644 --- a/homeassistant/components/baf/sensor.py +++ b/homeassistant/components/baf/sensor.py @@ -39,7 +39,7 @@ class BAFSensorDescription( """Class describing BAF sensor entities.""" -BASE_SENSORS = ( +AUTO_COMFORT_SENSORS = ( BAFSensorDescription( key="temperature", name="Temperature", @@ -103,10 +103,12 @@ async def async_setup_entry( """Set up BAF fan sensors.""" data: BAFData = hass.data[DOMAIN][entry.entry_id] device = data.device - sensors_descriptions = list(BASE_SENSORS) + sensors_descriptions: list[BAFSensorDescription] = [] for description in DEFINED_ONLY_SENSORS: if getattr(device, description.key): sensors_descriptions.append(description) + if device.has_auto_comfort: + sensors_descriptions.extend(AUTO_COMFORT_SENSORS) if device.has_fan: sensors_descriptions.extend(FAN_SENSORS) async_add_entities( diff --git a/homeassistant/components/baf/switch.py b/homeassistant/components/baf/switch.py index 6cefa0db65d..44671e68458 100644 --- a/homeassistant/components/baf/switch.py +++ b/homeassistant/components/baf/switch.py @@ -48,13 +48,16 @@ BASE_SWITCHES = [ ), ] -FAN_SWITCHES = [ +AUTO_COMFORT_SWITCHES = [ BAFSwitchDescription( key="comfort_heat_assist_enable", name="Auto Comfort Heat Assist", entity_category=EntityCategory.CONFIG, value_fn=lambda device: cast(Optional[bool], device.comfort_heat_assist_enable), ), +] + +FAN_SWITCHES = [ BAFSwitchDescription( key="fan_beep_enable", name="Beep", @@ -120,6 +123,8 @@ async def async_setup_entry( descriptions.extend(FAN_SWITCHES) if device.has_light: descriptions.extend(LIGHT_SWITCHES) + if device.has_auto_comfort: + descriptions.extend(AUTO_COMFORT_SWITCHES) async_add_entities(BAFSwitch(device, description) for description in descriptions) diff --git a/requirements_all.txt b/requirements_all.txt index 3abb93968bc..35b82892119 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -122,7 +122,7 @@ aioasuswrt==1.4.0 aioazuredevops==1.3.5 # homeassistant.components.baf -aiobafi6==0.3.0 +aiobafi6==0.5.0 # homeassistant.components.aws aiobotocore==2.1.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 148ce2191ba..a4753b643fb 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -109,7 +109,7 @@ aioasuswrt==1.4.0 aioazuredevops==1.3.5 # homeassistant.components.baf -aiobafi6==0.3.0 +aiobafi6==0.5.0 # homeassistant.components.aws aiobotocore==2.1.0