From 7b78862a11ffbf7d3ff30082f0af4738ce3848b4 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Fri, 7 Jan 2022 11:38:48 +0100 Subject: [PATCH] Revert "Use Platform enum [emulated_hue] (#63498)" (#63576) This reverts commit 4fd555f5083fa55b10d83abca0cefa6b04eee5ef. --- .../components/emulated_hue/hue_api.py | 50 +++++++++++-------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/emulated_hue/hue_api.py b/homeassistant/components/emulated_hue/hue_api.py index 2004d8cff9d..6e387f2fe26 100644 --- a/homeassistant/components/emulated_hue/hue_api.py +++ b/homeassistant/components/emulated_hue/hue_api.py @@ -7,7 +7,16 @@ import logging import time from homeassistant import core -from homeassistant.components import light, script +from homeassistant.components import ( + climate, + cover, + fan, + humidifier, + light, + media_player, + scene, + script, +) from homeassistant.components.climate.const import ( SERVICE_SET_TEMPERATURE, SUPPORT_TARGET_TEMPERATURE, @@ -55,7 +64,6 @@ from homeassistant.const import ( STATE_OFF, STATE_ON, STATE_UNAVAILABLE, - Platform, ) from homeassistant.helpers.event import async_track_state_change_event from homeassistant.util.network import is_local @@ -339,7 +347,7 @@ class HueOneLightChangeView(HomeAssistantView): # Get the entity's supported features entity_features = entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0) - if entity.domain == Platform.LIGHT: + if entity.domain == light.DOMAIN: color_modes = entity.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES, []) # Parse the request @@ -385,23 +393,23 @@ class HueOneLightChangeView(HomeAssistantView): return self.json_message("Bad request", HTTPStatus.BAD_REQUEST) if HUE_API_STATE_BRI in request_json: - if entity.domain == Platform.LIGHT: + if entity.domain == light.DOMAIN: if light.brightness_supported(color_modes): parsed[STATE_ON] = parsed[STATE_BRIGHTNESS] > 0 else: parsed[STATE_BRIGHTNESS] = None - elif entity.domain == Platform.SCENE: + elif entity.domain == scene.DOMAIN: parsed[STATE_BRIGHTNESS] = None parsed[STATE_ON] = True elif entity.domain in [ script.DOMAIN, - Platform.MEDIA_PLAYER, - Platform.FAN, - Platform.COVER, - Platform.CLIMATE, - Platform.HUMIDIFIER, + media_player.DOMAIN, + fan.DOMAIN, + cover.DOMAIN, + climate.DOMAIN, + humidifier.DOMAIN, ]: # Convert 0-254 to 0-100 level = (parsed[STATE_BRIGHTNESS] / HUE_API_STATE_BRI_MAX) * 100 @@ -422,7 +430,7 @@ class HueOneLightChangeView(HomeAssistantView): # If the requested entity is a light, set the brightness, hue, # saturation and color temp - if entity.domain == Platform.LIGHT: + if entity.domain == light.DOMAIN: if parsed[STATE_ON]: if ( light.brightness_supported(color_modes) @@ -475,7 +483,7 @@ class HueOneLightChangeView(HomeAssistantView): data["variables"]["requested_level"] = parsed[STATE_BRIGHTNESS] # If the requested entity is a climate, set the temperature - elif entity.domain == Platform.CLIMATE: + elif entity.domain == climate.DOMAIN: # We don't support turning climate devices on or off, # only setting the temperature service = None @@ -489,7 +497,7 @@ class HueOneLightChangeView(HomeAssistantView): data[ATTR_TEMPERATURE] = parsed[STATE_BRIGHTNESS] # If the requested entity is a humidifier, set the humidity - elif entity.domain == Platform.HUMIDIFIER: + elif entity.domain == humidifier.DOMAIN: if parsed[STATE_BRIGHTNESS] is not None: turn_on_needed = True domain = entity.domain @@ -497,7 +505,7 @@ class HueOneLightChangeView(HomeAssistantView): data[ATTR_HUMIDITY] = parsed[STATE_BRIGHTNESS] # If the requested entity is a media player, convert to volume - elif entity.domain == Platform.MEDIA_PLAYER: + elif entity.domain == media_player.DOMAIN: if ( entity_features & SUPPORT_VOLUME_SET and parsed[STATE_BRIGHTNESS] is not None @@ -509,7 +517,7 @@ class HueOneLightChangeView(HomeAssistantView): data[ATTR_MEDIA_VOLUME_LEVEL] = parsed[STATE_BRIGHTNESS] / 100.0 # If the requested entity is a cover, convert to open_cover/close_cover - elif entity.domain == Platform.COVER: + elif entity.domain == cover.DOMAIN: domain = entity.domain if service == SERVICE_TURN_ON: service = SERVICE_OPEN_COVER @@ -526,7 +534,7 @@ class HueOneLightChangeView(HomeAssistantView): # If the requested entity is a fan, convert to speed elif ( - entity.domain == Platform.FAN + entity.domain == fan.DOMAIN and entity_features & SUPPORT_SET_SPEED and parsed[STATE_BRIGHTNESS] is not None ): @@ -656,21 +664,21 @@ def get_entity_state(config, entity): data[STATE_SATURATION] = 0 data[STATE_COLOR_TEMP] = 0 - if entity.domain == Platform.CLIMATE: + if entity.domain == climate.DOMAIN: temperature = entity.attributes.get(ATTR_TEMPERATURE, 0) # Convert 0-100 to 0-254 data[STATE_BRIGHTNESS] = round(temperature * HUE_API_STATE_BRI_MAX / 100) - elif entity.domain == Platform.HUMIDIFIER: + elif entity.domain == humidifier.DOMAIN: humidity = entity.attributes.get(ATTR_HUMIDITY, 0) # Convert 0-100 to 0-254 data[STATE_BRIGHTNESS] = round(humidity * HUE_API_STATE_BRI_MAX / 100) - elif entity.domain == Platform.MEDIA_PLAYER: + elif entity.domain == media_player.DOMAIN: level = entity.attributes.get( ATTR_MEDIA_VOLUME_LEVEL, 1.0 if data[STATE_ON] else 0.0 ) # Convert 0.0-1.0 to 0-254 data[STATE_BRIGHTNESS] = round(min(1.0, level) * HUE_API_STATE_BRI_MAX) - elif entity.domain == Platform.FAN: + elif entity.domain == fan.DOMAIN: speed = entity.attributes.get(ATTR_SPEED, 0) # Convert 0.0-1.0 to 0-254 data[STATE_BRIGHTNESS] = 0 @@ -680,7 +688,7 @@ def get_entity_state(config, entity): data[STATE_BRIGHTNESS] = 170 elif speed == SPEED_HIGH: data[STATE_BRIGHTNESS] = HUE_API_STATE_BRI_MAX - elif entity.domain == Platform.COVER: + elif entity.domain == cover.DOMAIN: level = entity.attributes.get(ATTR_CURRENT_POSITION, 0) data[STATE_BRIGHTNESS] = round(level / 100 * HUE_API_STATE_BRI_MAX) else: