From 05c177e3edf2a2c199612054d4755e0cd697db8c Mon Sep 17 00:00:00 2001 From: Mick Vleeshouwer Date: Mon, 17 Jan 2022 12:25:24 -0800 Subject: [PATCH] Address late feedback to Overkiz (move to constants) (#64324) --- homeassistant/components/overkiz/binary_sensor.py | 10 +++++----- homeassistant/components/overkiz/button.py | 10 +++++----- homeassistant/components/overkiz/number.py | 8 +++----- homeassistant/components/overkiz/select.py | 8 +++----- homeassistant/components/overkiz/sensor.py | 8 +++----- 5 files changed, 19 insertions(+), 25 deletions(-) diff --git a/homeassistant/components/overkiz/binary_sensor.py b/homeassistant/components/overkiz/binary_sensor.py index e3ac11c98f9..2f4b11d6b13 100644 --- a/homeassistant/components/overkiz/binary_sensor.py +++ b/homeassistant/components/overkiz/binary_sensor.py @@ -102,6 +102,10 @@ BINARY_SENSOR_DESCRIPTIONS: list[OverkizBinarySensorDescription] = [ ), ] +SUPPORTED_STATES = { + description.key: description for description in BINARY_SENSOR_DESCRIPTIONS +} + async def async_setup_entry( hass: HomeAssistant, @@ -112,10 +116,6 @@ async def async_setup_entry( data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id] entities: list[OverkizBinarySensor] = [] - key_supported_states = { - description.key: description for description in BINARY_SENSOR_DESCRIPTIONS - } - for device in data.coordinator.data.values(): if ( device.widget in IGNORED_OVERKIZ_DEVICES @@ -124,7 +124,7 @@ async def async_setup_entry( continue for state in device.definition.states: - if description := key_supported_states.get(state.qualified_name): + if description := SUPPORTED_STATES.get(state.qualified_name): entities.append( OverkizBinarySensor( device.device_url, diff --git a/homeassistant/components/overkiz/button.py b/homeassistant/components/overkiz/button.py index 1977669303a..d14c744c8f7 100644 --- a/homeassistant/components/overkiz/button.py +++ b/homeassistant/components/overkiz/button.py @@ -48,6 +48,10 @@ BUTTON_DESCRIPTIONS: list[ButtonEntityDescription] = [ ButtonEntityDescription(key="ring", name="Ring", icon="mdi:bell-ring"), ] +SUPPORTED_COMMANDS = { + description.key: description for description in BUTTON_DESCRIPTIONS +} + async def async_setup_entry( hass: HomeAssistant, @@ -58,10 +62,6 @@ async def async_setup_entry( data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id] entities: list[ButtonEntity] = [] - supported_commands = { - description.key: description for description in BUTTON_DESCRIPTIONS - } - for device in data.coordinator.data.values(): if ( device.widget in IGNORED_OVERKIZ_DEVICES @@ -70,7 +70,7 @@ async def async_setup_entry( continue for command in device.definition.commands: - if description := supported_commands.get(command.command_name): + if description := SUPPORTED_COMMANDS.get(command.command_name): entities.append( OverkizButton( device.device_url, diff --git a/homeassistant/components/overkiz/number.py b/homeassistant/components/overkiz/number.py index e849e419e67..d0543eefd5e 100644 --- a/homeassistant/components/overkiz/number.py +++ b/homeassistant/components/overkiz/number.py @@ -50,6 +50,8 @@ NUMBER_DESCRIPTIONS: list[OverkizNumberDescription] = [ ), ] +SUPPORTED_STATES = {description.key: description for description in NUMBER_DESCRIPTIONS} + async def async_setup_entry( hass: HomeAssistant, @@ -60,10 +62,6 @@ async def async_setup_entry( data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id] entities: list[OverkizNumber] = [] - key_supported_states = { - description.key: description for description in NUMBER_DESCRIPTIONS - } - for device in data.coordinator.data.values(): if ( device.widget in IGNORED_OVERKIZ_DEVICES @@ -72,7 +70,7 @@ async def async_setup_entry( continue for state in device.definition.states: - if description := key_supported_states.get(state.qualified_name): + if description := SUPPORTED_STATES.get(state.qualified_name): entities.append( OverkizNumber( device.device_url, diff --git a/homeassistant/components/overkiz/select.py b/homeassistant/components/overkiz/select.py index 174a2553516..f1e48d83469 100644 --- a/homeassistant/components/overkiz/select.py +++ b/homeassistant/components/overkiz/select.py @@ -75,6 +75,8 @@ SELECT_DESCRIPTIONS: list[OverkizSelectDescription] = [ ), ] +SUPPORTED_STATES = {description.key: description for description in SELECT_DESCRIPTIONS} + async def async_setup_entry( hass: HomeAssistant, @@ -85,10 +87,6 @@ async def async_setup_entry( data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id] entities: list[OverkizSelect] = [] - key_supported_states = { - description.key: description for description in SELECT_DESCRIPTIONS - } - for device in data.coordinator.data.values(): if ( device.widget in IGNORED_OVERKIZ_DEVICES @@ -97,7 +95,7 @@ async def async_setup_entry( continue for state in device.definition.states: - if description := key_supported_states.get(state.qualified_name): + if description := SUPPORTED_STATES.get(state.qualified_name): entities.append( OverkizSelect( device.device_url, diff --git a/homeassistant/components/overkiz/sensor.py b/homeassistant/components/overkiz/sensor.py index 62358184ff9..3c16c360e39 100644 --- a/homeassistant/components/overkiz/sensor.py +++ b/homeassistant/components/overkiz/sensor.py @@ -344,6 +344,8 @@ SENSOR_DESCRIPTIONS: list[OverkizSensorDescription] = [ ), ] +SUPPORTED_STATES = {description.key: description for description in SENSOR_DESCRIPTIONS} + async def async_setup_entry( hass: HomeAssistant, @@ -354,10 +356,6 @@ async def async_setup_entry( data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id] entities: list[SensorEntity] = [] - key_supported_states = { - description.key: description for description in SENSOR_DESCRIPTIONS - } - for device in data.coordinator.data.values(): if device.widget == UIWidget.HOMEKIT_STACK: entities.append( @@ -374,7 +372,7 @@ async def async_setup_entry( continue for state in device.definition.states: - if description := key_supported_states.get(state.qualified_name): + if description := SUPPORTED_STATES.get(state.qualified_name): entities.append( OverkizStateSensor( device.device_url,