Only create auto comfort entities for BAF devices that support them (#72948)

This commit is contained in:
J. Nick Koston 2022-06-02 17:51:27 -10:00 committed by GitHub
parent 43b802252a
commit f52fa3599f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 40 additions and 28 deletions

View File

@ -26,7 +26,7 @@ async def async_setup_entry(
) -> None: ) -> None:
"""Set up BAF fan auto comfort.""" """Set up BAF fan auto comfort."""
data: BAFData = hass.data[DOMAIN][entry.entry_id] 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( async_add_entities(
[BAFAutoComfort(data.device, f"{data.device.name} Auto Comfort")] [BAFAutoComfort(data.device, f"{data.device.name} Auto Comfort")]
) )

View File

@ -3,7 +3,7 @@
"name": "Big Ass Fans", "name": "Big Ass Fans",
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/baf", "documentation": "https://www.home-assistant.io/integrations/baf",
"requirements": ["aiobafi6==0.3.0"], "requirements": ["aiobafi6==0.5.0"],
"codeowners": ["@bdraco", "@jfroy"], "codeowners": ["@bdraco", "@jfroy"],
"iot_class": "local_push", "iot_class": "local_push",
"zeroconf": [ "zeroconf": [

View File

@ -36,27 +36,7 @@ class BAFNumberDescription(NumberEntityDescription, BAFNumberDescriptionMixin):
"""Class describing BAF sensor entities.""" """Class describing BAF sensor entities."""
FAN_NUMBER_DESCRIPTIONS = ( AUTO_COMFORT_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,
),
BAFNumberDescription( BAFNumberDescription(
key="comfort_min_speed", key="comfort_min_speed",
name="Auto Comfort Minimum 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 = ( LIGHT_NUMBER_DESCRIPTIONS = (
BAFNumberDescription( BAFNumberDescription(
key="light_return_to_auto_timeout", key="light_return_to_auto_timeout",
@ -125,6 +128,8 @@ async def async_setup_entry(
descriptions.extend(FAN_NUMBER_DESCRIPTIONS) descriptions.extend(FAN_NUMBER_DESCRIPTIONS)
if device.has_light: if device.has_light:
descriptions.extend(LIGHT_NUMBER_DESCRIPTIONS) 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) async_add_entities(BAFNumber(device, description) for description in descriptions)

View File

@ -39,7 +39,7 @@ class BAFSensorDescription(
"""Class describing BAF sensor entities.""" """Class describing BAF sensor entities."""
BASE_SENSORS = ( AUTO_COMFORT_SENSORS = (
BAFSensorDescription( BAFSensorDescription(
key="temperature", key="temperature",
name="Temperature", name="Temperature",
@ -103,10 +103,12 @@ async def async_setup_entry(
"""Set up BAF fan sensors.""" """Set up BAF fan sensors."""
data: BAFData = hass.data[DOMAIN][entry.entry_id] data: BAFData = hass.data[DOMAIN][entry.entry_id]
device = data.device device = data.device
sensors_descriptions = list(BASE_SENSORS) sensors_descriptions: list[BAFSensorDescription] = []
for description in DEFINED_ONLY_SENSORS: for description in DEFINED_ONLY_SENSORS:
if getattr(device, description.key): if getattr(device, description.key):
sensors_descriptions.append(description) sensors_descriptions.append(description)
if device.has_auto_comfort:
sensors_descriptions.extend(AUTO_COMFORT_SENSORS)
if device.has_fan: if device.has_fan:
sensors_descriptions.extend(FAN_SENSORS) sensors_descriptions.extend(FAN_SENSORS)
async_add_entities( async_add_entities(

View File

@ -48,13 +48,16 @@ BASE_SWITCHES = [
), ),
] ]
FAN_SWITCHES = [ AUTO_COMFORT_SWITCHES = [
BAFSwitchDescription( BAFSwitchDescription(
key="comfort_heat_assist_enable", key="comfort_heat_assist_enable",
name="Auto Comfort Heat Assist", name="Auto Comfort Heat Assist",
entity_category=EntityCategory.CONFIG, entity_category=EntityCategory.CONFIG,
value_fn=lambda device: cast(Optional[bool], device.comfort_heat_assist_enable), value_fn=lambda device: cast(Optional[bool], device.comfort_heat_assist_enable),
), ),
]
FAN_SWITCHES = [
BAFSwitchDescription( BAFSwitchDescription(
key="fan_beep_enable", key="fan_beep_enable",
name="Beep", name="Beep",
@ -120,6 +123,8 @@ async def async_setup_entry(
descriptions.extend(FAN_SWITCHES) descriptions.extend(FAN_SWITCHES)
if device.has_light: if device.has_light:
descriptions.extend(LIGHT_SWITCHES) descriptions.extend(LIGHT_SWITCHES)
if device.has_auto_comfort:
descriptions.extend(AUTO_COMFORT_SWITCHES)
async_add_entities(BAFSwitch(device, description) for description in descriptions) async_add_entities(BAFSwitch(device, description) for description in descriptions)

View File

@ -122,7 +122,7 @@ aioasuswrt==1.4.0
aioazuredevops==1.3.5 aioazuredevops==1.3.5
# homeassistant.components.baf # homeassistant.components.baf
aiobafi6==0.3.0 aiobafi6==0.5.0
# homeassistant.components.aws # homeassistant.components.aws
aiobotocore==2.1.0 aiobotocore==2.1.0

View File

@ -109,7 +109,7 @@ aioasuswrt==1.4.0
aioazuredevops==1.3.5 aioazuredevops==1.3.5
# homeassistant.components.baf # homeassistant.components.baf
aiobafi6==0.3.0 aiobafi6==0.5.0
# homeassistant.components.aws # homeassistant.components.aws
aiobotocore==2.1.0 aiobotocore==2.1.0