This commit is contained in:
Paulus Schoutsen committed 2019-07-31 12:25:30 -07:00
1 parent da05dfe708
commit 4de97abc3a
2676 files changed
+163166 -140084

No files matched your search

+133 -81
View File
@@ -8,12 +8,18 @@ from pysmartthings import Attribute, Capability
import pytest
from homeassistant.components.light import (
ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_HS_COLOR, ATTR_TRANSITION,
DOMAIN as LIGHT_DOMAIN, SUPPORT_BRIGHTNESS, SUPPORT_COLOR,
SUPPORT_COLOR_TEMP, SUPPORT_TRANSITION)
ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP,
ATTR_HS_COLOR,
ATTR_TRANSITION,
DOMAIN as LIGHT_DOMAIN,
SUPPORT_BRIGHTNESS,
SUPPORT_COLOR,
SUPPORT_COLOR_TEMP,
SUPPORT_TRANSITION,
)
from homeassistant.components.smartthings import light
from homeassistant.components.smartthings.const import (
DOMAIN, SIGNAL_SMARTTHINGS_UPDATE)
from homeassistant.components.smartthings.const import DOMAIN, SIGNAL_SMARTTHINGS_UPDATE
from homeassistant.const import ATTR_ENTITY_ID, ATTR_SUPPORTED_FEATURES
from homeassistant.helpers.dispatcher import async_dispatcher_send
@@ -27,21 +33,38 @@ def light_devices_fixture(device_factory):
device_factory(
"Dimmer 1",
capabilities=[Capability.switch, Capability.switch_level],
status={Attribute.switch: 'on', Attribute.level: 100}),
status={Attribute.switch: "on", Attribute.level: 100},
),
device_factory(
"Color Dimmer 1",
capabilities=[Capability.switch, Capability.switch_level,
Capability.color_control],
status={Attribute.switch: 'off', Attribute.level: 0,
Attribute.hue: 76.0, Attribute.saturation: 55.0}),
capabilities=[
Capability.switch,
Capability.switch_level,
Capability.color_control,
],
status={
Attribute.switch: "off",
Attribute.level: 0,
Attribute.hue: 76.0,
Attribute.saturation: 55.0,
},
),
device_factory(
"Color Dimmer 2",
capabilities=[Capability.switch, Capability.switch_level,
Capability.color_control,
Capability.color_temperature],
status={Attribute.switch: 'on', Attribute.level: 100,
Attribute.hue: 76.0, Attribute.saturation: 55.0,
Attribute.color_temperature: 4500})
capabilities=[
Capability.switch,
Capability.switch_level,
Capability.color_control,
Capability.color_temperature,
],
status={
Attribute.switch: "on",
Attribute.level: 100,
Attribute.hue: 76.0,
Attribute.saturation: 55.0,
Attribute.color_temperature: 4500,
},
),
]
@@ -55,24 +78,29 @@ async def test_entity_state(hass, light_devices):
await setup_platform(hass, LIGHT_DOMAIN, devices=light_devices)
# Dimmer 1
state = hass.states.get('light.dimmer_1')
assert state.state == 'on'
assert state.attributes[ATTR_SUPPORTED_FEATURES] == \
SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION
state = hass.states.get("light.dimmer_1")
assert state.state == "on"
assert (
state.attributes[ATTR_SUPPORTED_FEATURES]
== SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION
)
assert state.attributes[ATTR_BRIGHTNESS] == 255
# Color Dimmer 1
state = hass.states.get('light.color_dimmer_1')
assert state.state == 'off'
assert state.attributes[ATTR_SUPPORTED_FEATURES] == \
SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION | SUPPORT_COLOR
state = hass.states.get("light.color_dimmer_1")
assert state.state == "off"
assert (
state.attributes[ATTR_SUPPORTED_FEATURES]
== SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION | SUPPORT_COLOR
)
# Color Dimmer 2
state = hass.states.get('light.color_dimmer_2')
assert state.state == 'on'
assert state.attributes[ATTR_SUPPORTED_FEATURES] == \
SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION | SUPPORT_COLOR | \
SUPPORT_COLOR_TEMP
state = hass.states.get("light.color_dimmer_2")
assert state.state == "on"
assert (
state.attributes[ATTR_SUPPORTED_FEATURES]
== SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION | SUPPORT_COLOR | SUPPORT_COLOR_TEMP
)
assert state.attributes[ATTR_BRIGHTNESS] == 255
assert state.attributes[ATTR_HS_COLOR] == (273.6, 55.0)
assert state.attributes[ATTR_COLOR_TEMP] == 222
@@ -81,8 +109,7 @@ async def test_entity_state(hass, light_devices):
async def test_entity_and_device_attributes(hass, device_factory):
"""Test the attributes of the entity are correct."""
# Arrange
device = device_factory(
"Light 1", [Capability.switch, Capability.switch_level])
device = device_factory("Light 1", [Capability.switch, Capability.switch_level])
entity_registry = await hass.helpers.entity_registry.async_get_registry()
device_registry = await hass.helpers.device_registry.async_get_registry()
# Act
@@ -92,12 +119,11 @@ async def test_entity_and_device_attributes(hass, device_factory):
assert entry
assert entry.unique_id == device.device_id
entry = device_registry.async_get_device(
{(DOMAIN, device.device_id)}, [])
entry = device_registry.async_get_device({(DOMAIN, device.device_id)}, [])
assert entry
assert entry.name == device.label
assert entry.model == device.device_type_name
assert entry.manufacturer == 'Unavailable'
assert entry.manufacturer == "Unavailable"
async def test_turn_off(hass, light_devices):
@@ -106,12 +132,12 @@ async def test_turn_off(hass, light_devices):
await setup_platform(hass, LIGHT_DOMAIN, devices=light_devices)
# Act
await hass.services.async_call(
'light', 'turn_off', {'entity_id': 'light.color_dimmer_2'},
blocking=True)
"light", "turn_off", {"entity_id": "light.color_dimmer_2"}, blocking=True
)
# Assert
state = hass.states.get('light.color_dimmer_2')
state = hass.states.get("light.color_dimmer_2")
assert state is not None
assert state.state == 'off'
assert state.state == "off"
async def test_turn_off_with_transition(hass, light_devices):
@@ -120,13 +146,15 @@ async def test_turn_off_with_transition(hass, light_devices):
await setup_platform(hass, LIGHT_DOMAIN, devices=light_devices)
# Act
await hass.services.async_call(
'light', 'turn_off',
"light",
"turn_off",
{ATTR_ENTITY_ID: "light.color_dimmer_2", ATTR_TRANSITION: 2},
blocking=True)
blocking=True,
)
# Assert
state = hass.states.get("light.color_dimmer_2")
assert state is not None
assert state.state == 'off'
assert state.state == "off"
async def test_turn_on(hass, light_devices):
@@ -135,12 +163,12 @@ async def test_turn_on(hass, light_devices):
await setup_platform(hass, LIGHT_DOMAIN, devices=light_devices)
# Act
await hass.services.async_call(
'light', 'turn_on', {ATTR_ENTITY_ID: "light.color_dimmer_1"},
blocking=True)
"light", "turn_on", {ATTR_ENTITY_ID: "light.color_dimmer_1"}, blocking=True
)
# Assert
state = hass.states.get("light.color_dimmer_1")
assert state is not None
assert state.state == 'on'
assert state.state == "on"
async def test_turn_on_with_brightness(hass, light_devices):
@@ -149,14 +177,19 @@ async def test_turn_on_with_brightness(hass, light_devices):
await setup_platform(hass, LIGHT_DOMAIN, devices=light_devices)
# Act
await hass.services.async_call(
'light', 'turn_on',
{ATTR_ENTITY_ID: "light.color_dimmer_1",
ATTR_BRIGHTNESS: 75, ATTR_TRANSITION: 2},
blocking=True)
"light",
"turn_on",
{
ATTR_ENTITY_ID: "light.color_dimmer_1",
ATTR_BRIGHTNESS: 75,
ATTR_TRANSITION: 2,
},
blocking=True,
)
# Assert
state = hass.states.get("light.color_dimmer_1")
assert state is not None
assert state.state == 'on'
assert state.state == "on"
# round-trip rounding error (expected)
assert state.attributes[ATTR_BRIGHTNESS] == 73.95
@@ -173,14 +206,15 @@ async def test_turn_on_with_minimal_brightness(hass, light_devices):
await setup_platform(hass, LIGHT_DOMAIN, devices=light_devices)
# Act
await hass.services.async_call(
'light', 'turn_on',
{ATTR_ENTITY_ID: "light.color_dimmer_1",
ATTR_BRIGHTNESS: 2},
blocking=True)
"light",
"turn_on",
{ATTR_ENTITY_ID: "light.color_dimmer_1", ATTR_BRIGHTNESS: 2},
blocking=True,
)
# Assert
state = hass.states.get("light.color_dimmer_1")
assert state is not None
assert state.state == 'on'
assert state.state == "on"
# round-trip rounding error (expected)
assert state.attributes[ATTR_BRIGHTNESS] == 2.55
@@ -191,14 +225,15 @@ async def test_turn_on_with_color(hass, light_devices):
await setup_platform(hass, LIGHT_DOMAIN, devices=light_devices)
# Act
await hass.services.async_call(
'light', 'turn_on',
{ATTR_ENTITY_ID: "light.color_dimmer_2",
ATTR_HS_COLOR: (180, 50)},
blocking=True)
"light",
"turn_on",
{ATTR_ENTITY_ID: "light.color_dimmer_2", ATTR_HS_COLOR: (180, 50)},
blocking=True,
)
# Assert
state = hass.states.get("light.color_dimmer_2")
assert state is not None
assert state.state == 'on'
assert state.state == "on"
assert state.attributes[ATTR_HS_COLOR] == (180, 50)
@@ -208,14 +243,15 @@ async def test_turn_on_with_color_temp(hass, light_devices):
await setup_platform(hass, LIGHT_DOMAIN, devices=light_devices)
# Act
await hass.services.async_call(
'light', 'turn_on',
{ATTR_ENTITY_ID: "light.color_dimmer_2",
ATTR_COLOR_TEMP: 300},
blocking=True)
"light",
"turn_on",
{ATTR_ENTITY_ID: "light.color_dimmer_2", ATTR_COLOR_TEMP: 300},
blocking=True,
)
# Assert
state = hass.states.get("light.color_dimmer_2")
assert state is not None
assert state.state == 'on'
assert state.state == "on"
assert state.attributes[ATTR_COLOR_TEMP] == 300
@@ -224,21 +260,29 @@ async def test_update_from_signal(hass, device_factory):
# Arrange
device = device_factory(
"Color Dimmer 2",
capabilities=[Capability.switch, Capability.switch_level,
Capability.color_control, Capability.color_temperature],
status={Attribute.switch: 'off', Attribute.level: 100,
Attribute.hue: 76.0, Attribute.saturation: 55.0,
Attribute.color_temperature: 4500})
capabilities=[
Capability.switch,
Capability.switch_level,
Capability.color_control,
Capability.color_temperature,
],
status={
Attribute.switch: "off",
Attribute.level: 100,
Attribute.hue: 76.0,
Attribute.saturation: 55.0,
Attribute.color_temperature: 4500,
},
)
await setup_platform(hass, LIGHT_DOMAIN, devices=[device])
await device.switch_on(True)
# Act
async_dispatcher_send(hass, SIGNAL_SMARTTHINGS_UPDATE,
[device.device_id])
async_dispatcher_send(hass, SIGNAL_SMARTTHINGS_UPDATE, [device.device_id])
# Assert
await hass.async_block_till_done()
state = hass.states.get('light.color_dimmer_2')
state = hass.states.get("light.color_dimmer_2")
assert state is not None
assert state.state == 'on'
assert state.state == "on"
async def test_unload_config_entry(hass, device_factory):
@@ -246,14 +290,22 @@ async def test_unload_config_entry(hass, device_factory):
# Arrange
device = device_factory(
"Color Dimmer 2",
capabilities=[Capability.switch, Capability.switch_level,
Capability.color_control, Capability.color_temperature],
status={Attribute.switch: 'off', Attribute.level: 100,
Attribute.hue: 76.0, Attribute.saturation: 55.0,
Attribute.color_temperature: 4500})
capabilities=[
Capability.switch,
Capability.switch_level,
Capability.color_control,
Capability.color_temperature,
],
status={
Attribute.switch: "off",
Attribute.level: 100,
Attribute.hue: 76.0,
Attribute.saturation: 55.0,
Attribute.color_temperature: 4500,
},
)
config_entry = await setup_platform(hass, LIGHT_DOMAIN, devices=[device])
# Act
await hass.config_entries.async_forward_entry_unload(
config_entry, 'light')
await hass.config_entries.async_forward_entry_unload(config_entry, "light")
# Assert
assert not hass.states.get('light.color_dimmer_2')
assert not hass.states.get("light.color_dimmer_2")