mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Set cover level using emulated_hue (#19594)
* set cover level using emulated_hue * changed mapping for service turn_on/off for cover. * removed whitespace for the sake of hound * using const for domains instead of hardcoded strings. * change length of lines for the sake of hound * fixed under-intended line * changed intent for the sake of hound
This commit is contained in:
committed by
Charles Garwood
parent
788f7988e7
commit
49ecca9cb9
@@ -19,6 +19,16 @@ from homeassistant.components.fan import (
|
||||
ATTR_SPEED, SUPPORT_SET_SPEED, SPEED_OFF, SPEED_LOW,
|
||||
SPEED_MEDIUM, SPEED_HIGH
|
||||
)
|
||||
|
||||
from homeassistant.components.cover import (
|
||||
ATTR_CURRENT_POSITION, ATTR_POSITION, SERVICE_SET_COVER_POSITION,
|
||||
SUPPORT_SET_POSITION
|
||||
)
|
||||
|
||||
from homeassistant.components import (
|
||||
cover, fan, media_player, light, script, scene
|
||||
)
|
||||
|
||||
from homeassistant.components.http import HomeAssistantView
|
||||
from homeassistant.components.http.const import KEY_REAL_IP
|
||||
from homeassistant.util.network import is_local
|
||||
@@ -239,13 +249,13 @@ class HueOneLightChangeView(HomeAssistantView):
|
||||
# Make sure the entity actually supports brightness
|
||||
entity_features = entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
|
||||
|
||||
if entity.domain == "light":
|
||||
if entity.domain == light.DOMAIN:
|
||||
if entity_features & SUPPORT_BRIGHTNESS:
|
||||
if brightness is not None:
|
||||
data[ATTR_BRIGHTNESS] = brightness
|
||||
|
||||
# If the requested entity is a script add some variables
|
||||
elif entity.domain == "script":
|
||||
elif entity.domain == script.DOMAIN:
|
||||
data['variables'] = {
|
||||
'requested_state': STATE_ON if result else STATE_OFF
|
||||
}
|
||||
@@ -254,7 +264,7 @@ class HueOneLightChangeView(HomeAssistantView):
|
||||
data['variables']['requested_level'] = brightness
|
||||
|
||||
# If the requested entity is a media player, convert to volume
|
||||
elif entity.domain == "media_player":
|
||||
elif entity.domain == media_player.DOMAIN:
|
||||
if entity_features & SUPPORT_VOLUME_SET:
|
||||
if brightness is not None:
|
||||
turn_on_needed = True
|
||||
@@ -264,15 +274,21 @@ class HueOneLightChangeView(HomeAssistantView):
|
||||
data[ATTR_MEDIA_VOLUME_LEVEL] = brightness / 100.0
|
||||
|
||||
# If the requested entity is a cover, convert to open_cover/close_cover
|
||||
elif entity.domain == "cover":
|
||||
elif entity.domain == cover.DOMAIN:
|
||||
domain = entity.domain
|
||||
if service == SERVICE_TURN_ON:
|
||||
service = SERVICE_OPEN_COVER
|
||||
else:
|
||||
service = SERVICE_CLOSE_COVER
|
||||
|
||||
if entity_features & SUPPORT_SET_POSITION:
|
||||
if brightness is not None:
|
||||
domain = entity.domain
|
||||
service = SERVICE_SET_COVER_POSITION
|
||||
data[ATTR_POSITION] = brightness
|
||||
|
||||
# If the requested entity is a fan, convert to speed
|
||||
elif entity.domain == "fan":
|
||||
elif entity.domain == fan.DOMAIN:
|
||||
if entity_features & SUPPORT_SET_SPEED:
|
||||
if brightness is not None:
|
||||
domain = entity.domain
|
||||
@@ -344,19 +360,19 @@ def parse_hue_api_put_light_body(request_json, entity):
|
||||
# Make sure the entity actually supports brightness
|
||||
entity_features = entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
|
||||
|
||||
if entity.domain == "light":
|
||||
if entity.domain == light.DOMAIN:
|
||||
if entity_features & SUPPORT_BRIGHTNESS:
|
||||
report_brightness = True
|
||||
result = (brightness > 0)
|
||||
|
||||
elif entity.domain == "scene":
|
||||
elif entity.domain == scene.DOMAIN:
|
||||
brightness = None
|
||||
report_brightness = False
|
||||
result = True
|
||||
|
||||
elif (entity.domain == "script" or
|
||||
entity.domain == "media_player" or
|
||||
entity.domain == "fan"):
|
||||
elif entity.domain in [
|
||||
script.DOMAIN, media_player.DOMAIN,
|
||||
fan.DOMAIN, cover.DOMAIN]:
|
||||
# Convert 0-255 to 0-100
|
||||
level = brightness / 255 * 100
|
||||
brightness = round(level)
|
||||
@@ -378,16 +394,16 @@ def get_entity_state(config, entity):
|
||||
# Make sure the entity actually supports brightness
|
||||
entity_features = entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
|
||||
|
||||
if entity.domain == "light":
|
||||
if entity.domain == light.DOMAIN:
|
||||
if entity_features & SUPPORT_BRIGHTNESS:
|
||||
pass
|
||||
|
||||
elif entity.domain == "media_player":
|
||||
elif entity.domain == media_player.DOMAIN:
|
||||
level = entity.attributes.get(
|
||||
ATTR_MEDIA_VOLUME_LEVEL, 1.0 if final_state else 0.0)
|
||||
# Convert 0.0-1.0 to 0-255
|
||||
final_brightness = round(min(1.0, level) * 255)
|
||||
elif entity.domain == "fan":
|
||||
elif entity.domain == fan.DOMAIN:
|
||||
speed = entity.attributes.get(ATTR_SPEED, 0)
|
||||
# Convert 0.0-1.0 to 0-255
|
||||
final_brightness = 0
|
||||
@@ -397,6 +413,9 @@ def get_entity_state(config, entity):
|
||||
final_brightness = 170
|
||||
elif speed == SPEED_HIGH:
|
||||
final_brightness = 255
|
||||
elif entity.domain == cover.DOMAIN:
|
||||
level = entity.attributes.get(ATTR_CURRENT_POSITION, 0)
|
||||
final_brightness = round(level / 100 * 255)
|
||||
else:
|
||||
final_state, final_brightness = cached_state
|
||||
# Make sure brightness is valid
|
||||
|
||||
Reference in New Issue
Block a user