This reverts commit 4fd555f508
.
pull/63587/head
parent
8bf8709d99
commit
7b78862a11
|
@ -7,7 +7,16 @@ import logging
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from homeassistant import core
|
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 (
|
from homeassistant.components.climate.const import (
|
||||||
SERVICE_SET_TEMPERATURE,
|
SERVICE_SET_TEMPERATURE,
|
||||||
SUPPORT_TARGET_TEMPERATURE,
|
SUPPORT_TARGET_TEMPERATURE,
|
||||||
|
@ -55,7 +64,6 @@ from homeassistant.const import (
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
STATE_UNAVAILABLE,
|
STATE_UNAVAILABLE,
|
||||||
Platform,
|
|
||||||
)
|
)
|
||||||
from homeassistant.helpers.event import async_track_state_change_event
|
from homeassistant.helpers.event import async_track_state_change_event
|
||||||
from homeassistant.util.network import is_local
|
from homeassistant.util.network import is_local
|
||||||
|
@ -339,7 +347,7 @@ class HueOneLightChangeView(HomeAssistantView):
|
||||||
|
|
||||||
# Get the entity's supported features
|
# Get the entity's supported features
|
||||||
entity_features = entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
|
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, [])
|
color_modes = entity.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES, [])
|
||||||
|
|
||||||
# Parse the request
|
# Parse the request
|
||||||
|
@ -385,23 +393,23 @@ class HueOneLightChangeView(HomeAssistantView):
|
||||||
return self.json_message("Bad request", HTTPStatus.BAD_REQUEST)
|
return self.json_message("Bad request", HTTPStatus.BAD_REQUEST)
|
||||||
|
|
||||||
if HUE_API_STATE_BRI in request_json:
|
if HUE_API_STATE_BRI in request_json:
|
||||||
if entity.domain == Platform.LIGHT:
|
if entity.domain == light.DOMAIN:
|
||||||
if light.brightness_supported(color_modes):
|
if light.brightness_supported(color_modes):
|
||||||
parsed[STATE_ON] = parsed[STATE_BRIGHTNESS] > 0
|
parsed[STATE_ON] = parsed[STATE_BRIGHTNESS] > 0
|
||||||
else:
|
else:
|
||||||
parsed[STATE_BRIGHTNESS] = None
|
parsed[STATE_BRIGHTNESS] = None
|
||||||
|
|
||||||
elif entity.domain == Platform.SCENE:
|
elif entity.domain == scene.DOMAIN:
|
||||||
parsed[STATE_BRIGHTNESS] = None
|
parsed[STATE_BRIGHTNESS] = None
|
||||||
parsed[STATE_ON] = True
|
parsed[STATE_ON] = True
|
||||||
|
|
||||||
elif entity.domain in [
|
elif entity.domain in [
|
||||||
script.DOMAIN,
|
script.DOMAIN,
|
||||||
Platform.MEDIA_PLAYER,
|
media_player.DOMAIN,
|
||||||
Platform.FAN,
|
fan.DOMAIN,
|
||||||
Platform.COVER,
|
cover.DOMAIN,
|
||||||
Platform.CLIMATE,
|
climate.DOMAIN,
|
||||||
Platform.HUMIDIFIER,
|
humidifier.DOMAIN,
|
||||||
]:
|
]:
|
||||||
# Convert 0-254 to 0-100
|
# Convert 0-254 to 0-100
|
||||||
level = (parsed[STATE_BRIGHTNESS] / HUE_API_STATE_BRI_MAX) * 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,
|
# If the requested entity is a light, set the brightness, hue,
|
||||||
# saturation and color temp
|
# saturation and color temp
|
||||||
if entity.domain == Platform.LIGHT:
|
if entity.domain == light.DOMAIN:
|
||||||
if parsed[STATE_ON]:
|
if parsed[STATE_ON]:
|
||||||
if (
|
if (
|
||||||
light.brightness_supported(color_modes)
|
light.brightness_supported(color_modes)
|
||||||
|
@ -475,7 +483,7 @@ class HueOneLightChangeView(HomeAssistantView):
|
||||||
data["variables"]["requested_level"] = parsed[STATE_BRIGHTNESS]
|
data["variables"]["requested_level"] = parsed[STATE_BRIGHTNESS]
|
||||||
|
|
||||||
# If the requested entity is a climate, set the temperature
|
# 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,
|
# We don't support turning climate devices on or off,
|
||||||
# only setting the temperature
|
# only setting the temperature
|
||||||
service = None
|
service = None
|
||||||
|
@ -489,7 +497,7 @@ class HueOneLightChangeView(HomeAssistantView):
|
||||||
data[ATTR_TEMPERATURE] = parsed[STATE_BRIGHTNESS]
|
data[ATTR_TEMPERATURE] = parsed[STATE_BRIGHTNESS]
|
||||||
|
|
||||||
# If the requested entity is a humidifier, set the humidity
|
# 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:
|
if parsed[STATE_BRIGHTNESS] is not None:
|
||||||
turn_on_needed = True
|
turn_on_needed = True
|
||||||
domain = entity.domain
|
domain = entity.domain
|
||||||
|
@ -497,7 +505,7 @@ class HueOneLightChangeView(HomeAssistantView):
|
||||||
data[ATTR_HUMIDITY] = parsed[STATE_BRIGHTNESS]
|
data[ATTR_HUMIDITY] = parsed[STATE_BRIGHTNESS]
|
||||||
|
|
||||||
# If the requested entity is a media player, convert to volume
|
# If the requested entity is a media player, convert to volume
|
||||||
elif entity.domain == Platform.MEDIA_PLAYER:
|
elif entity.domain == media_player.DOMAIN:
|
||||||
if (
|
if (
|
||||||
entity_features & SUPPORT_VOLUME_SET
|
entity_features & SUPPORT_VOLUME_SET
|
||||||
and parsed[STATE_BRIGHTNESS] is not None
|
and parsed[STATE_BRIGHTNESS] is not None
|
||||||
|
@ -509,7 +517,7 @@ class HueOneLightChangeView(HomeAssistantView):
|
||||||
data[ATTR_MEDIA_VOLUME_LEVEL] = parsed[STATE_BRIGHTNESS] / 100.0
|
data[ATTR_MEDIA_VOLUME_LEVEL] = parsed[STATE_BRIGHTNESS] / 100.0
|
||||||
|
|
||||||
# If the requested entity is a cover, convert to open_cover/close_cover
|
# 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
|
domain = entity.domain
|
||||||
if service == SERVICE_TURN_ON:
|
if service == SERVICE_TURN_ON:
|
||||||
service = SERVICE_OPEN_COVER
|
service = SERVICE_OPEN_COVER
|
||||||
|
@ -526,7 +534,7 @@ class HueOneLightChangeView(HomeAssistantView):
|
||||||
|
|
||||||
# If the requested entity is a fan, convert to speed
|
# If the requested entity is a fan, convert to speed
|
||||||
elif (
|
elif (
|
||||||
entity.domain == Platform.FAN
|
entity.domain == fan.DOMAIN
|
||||||
and entity_features & SUPPORT_SET_SPEED
|
and entity_features & SUPPORT_SET_SPEED
|
||||||
and parsed[STATE_BRIGHTNESS] is not None
|
and parsed[STATE_BRIGHTNESS] is not None
|
||||||
):
|
):
|
||||||
|
@ -656,21 +664,21 @@ def get_entity_state(config, entity):
|
||||||
data[STATE_SATURATION] = 0
|
data[STATE_SATURATION] = 0
|
||||||
data[STATE_COLOR_TEMP] = 0
|
data[STATE_COLOR_TEMP] = 0
|
||||||
|
|
||||||
if entity.domain == Platform.CLIMATE:
|
if entity.domain == climate.DOMAIN:
|
||||||
temperature = entity.attributes.get(ATTR_TEMPERATURE, 0)
|
temperature = entity.attributes.get(ATTR_TEMPERATURE, 0)
|
||||||
# Convert 0-100 to 0-254
|
# Convert 0-100 to 0-254
|
||||||
data[STATE_BRIGHTNESS] = round(temperature * HUE_API_STATE_BRI_MAX / 100)
|
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)
|
humidity = entity.attributes.get(ATTR_HUMIDITY, 0)
|
||||||
# Convert 0-100 to 0-254
|
# Convert 0-100 to 0-254
|
||||||
data[STATE_BRIGHTNESS] = round(humidity * HUE_API_STATE_BRI_MAX / 100)
|
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(
|
level = entity.attributes.get(
|
||||||
ATTR_MEDIA_VOLUME_LEVEL, 1.0 if data[STATE_ON] else 0.0
|
ATTR_MEDIA_VOLUME_LEVEL, 1.0 if data[STATE_ON] else 0.0
|
||||||
)
|
)
|
||||||
# Convert 0.0-1.0 to 0-254
|
# Convert 0.0-1.0 to 0-254
|
||||||
data[STATE_BRIGHTNESS] = round(min(1.0, level) * HUE_API_STATE_BRI_MAX)
|
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)
|
speed = entity.attributes.get(ATTR_SPEED, 0)
|
||||||
# Convert 0.0-1.0 to 0-254
|
# Convert 0.0-1.0 to 0-254
|
||||||
data[STATE_BRIGHTNESS] = 0
|
data[STATE_BRIGHTNESS] = 0
|
||||||
|
@ -680,7 +688,7 @@ def get_entity_state(config, entity):
|
||||||
data[STATE_BRIGHTNESS] = 170
|
data[STATE_BRIGHTNESS] = 170
|
||||||
elif speed == SPEED_HIGH:
|
elif speed == SPEED_HIGH:
|
||||||
data[STATE_BRIGHTNESS] = HUE_API_STATE_BRI_MAX
|
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)
|
level = entity.attributes.get(ATTR_CURRENT_POSITION, 0)
|
||||||
data[STATE_BRIGHTNESS] = round(level / 100 * HUE_API_STATE_BRI_MAX)
|
data[STATE_BRIGHTNESS] = round(level / 100 * HUE_API_STATE_BRI_MAX)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue