Add SmartThings climate support for Air Conditioners (#21840)
* Add support for Samsung Air Conditioners to Climate * Changes per review feedback. * Fix py3.5 compat list sorting in test
This commit is contained in:
parent
2d2abc7831
commit
c927cd9c14
2 changed files with 324 additions and 32 deletions
|
@ -13,14 +13,15 @@ from homeassistant.components.climate.const import (
|
|||
ATTR_FAN_MODE, ATTR_OPERATION_LIST, ATTR_OPERATION_MODE,
|
||||
ATTR_TARGET_TEMP_HIGH, ATTR_TARGET_TEMP_LOW, DOMAIN as CLIMATE_DOMAIN,
|
||||
SERVICE_SET_FAN_MODE, SERVICE_SET_OPERATION_MODE, SERVICE_SET_TEMPERATURE,
|
||||
STATE_AUTO, STATE_COOL, STATE_ECO, STATE_HEAT, SUPPORT_FAN_MODE,
|
||||
SUPPORT_OPERATION_MODE, SUPPORT_TARGET_TEMPERATURE,
|
||||
SUPPORT_TARGET_TEMPERATURE_HIGH, SUPPORT_TARGET_TEMPERATURE_LOW)
|
||||
STATE_AUTO, STATE_COOL, STATE_DRY, STATE_ECO, STATE_FAN_ONLY, STATE_HEAT,
|
||||
SUPPORT_FAN_MODE, SUPPORT_ON_OFF, SUPPORT_OPERATION_MODE,
|
||||
SUPPORT_TARGET_TEMPERATURE, SUPPORT_TARGET_TEMPERATURE_HIGH,
|
||||
SUPPORT_TARGET_TEMPERATURE_LOW)
|
||||
from homeassistant.components.smartthings import climate
|
||||
from homeassistant.components.smartthings.const import DOMAIN
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID, ATTR_SUPPORTED_FEATURES, ATTR_TEMPERATURE, STATE_OFF,
|
||||
STATE_UNKNOWN)
|
||||
ATTR_ENTITY_ID, ATTR_SUPPORTED_FEATURES, ATTR_TEMPERATURE,
|
||||
SERVICE_TURN_OFF, SERVICE_TURN_ON, STATE_OFF, STATE_UNKNOWN)
|
||||
|
||||
from .conftest import setup_platform
|
||||
|
||||
|
@ -115,6 +116,41 @@ def buggy_thermostat_fixture(device_factory):
|
|||
return device
|
||||
|
||||
|
||||
@pytest.fixture(name="air_conditioner")
|
||||
def air_conditioner_fixture(device_factory):
|
||||
"""Fixture returns a air conditioner."""
|
||||
device = device_factory(
|
||||
"Air Conditioner",
|
||||
capabilities=[
|
||||
Capability.air_conditioner_mode,
|
||||
Capability.demand_response_load_control,
|
||||
Capability.fan_speed,
|
||||
Capability.power_consumption_report,
|
||||
Capability.switch,
|
||||
Capability.temperature_measurement,
|
||||
Capability.thermostat_cooling_setpoint],
|
||||
status={
|
||||
Attribute.air_conditioner_mode: 'auto',
|
||||
Attribute.drlc_status: {
|
||||
"duration": 0,
|
||||
"drlcLevel": -1,
|
||||
"start": "1970-01-01T00:00:00Z",
|
||||
"override": False
|
||||
},
|
||||
Attribute.fan_speed: 2,
|
||||
Attribute.power_consumption: {
|
||||
"start": "2019-02-24T21:03:04Z",
|
||||
"power": 0,
|
||||
"energy": 500,
|
||||
"end": "2019-02-26T02:05:55Z"
|
||||
},
|
||||
Attribute.switch: 'on',
|
||||
Attribute.cooling_setpoint: 23}
|
||||
)
|
||||
device.status.attributes[Attribute.temperature] = Status(24, 'C', None)
|
||||
return device
|
||||
|
||||
|
||||
async def test_async_setup_platform():
|
||||
"""Test setup platform does nothing (it uses config entries)."""
|
||||
await climate.async_setup_platform(None, None, None)
|
||||
|
@ -195,28 +231,61 @@ async def test_buggy_thermostat_invalid_mode(hass, buggy_thermostat):
|
|||
assert state.attributes[ATTR_OPERATION_LIST] == {'heat'}
|
||||
|
||||
|
||||
async def test_set_fan_mode(hass, thermostat):
|
||||
async def test_air_conditioner_entity_state(hass, air_conditioner):
|
||||
"""Tests when an invalid operation mode is included."""
|
||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[air_conditioner])
|
||||
state = hass.states.get('climate.air_conditioner')
|
||||
assert state.state == STATE_AUTO
|
||||
assert state.attributes[ATTR_SUPPORTED_FEATURES] == \
|
||||
SUPPORT_OPERATION_MODE | SUPPORT_FAN_MODE | \
|
||||
SUPPORT_TARGET_TEMPERATURE | SUPPORT_ON_OFF
|
||||
assert sorted(state.attributes[ATTR_OPERATION_LIST]) == [
|
||||
STATE_AUTO, STATE_COOL, STATE_DRY, STATE_FAN_ONLY, STATE_HEAT]
|
||||
assert state.attributes[ATTR_FAN_MODE] == 'medium'
|
||||
assert sorted(state.attributes[ATTR_FAN_LIST]) == \
|
||||
['auto', 'high', 'low', 'medium', 'turbo']
|
||||
assert state.attributes[ATTR_TEMPERATURE] == 23
|
||||
assert state.attributes[ATTR_CURRENT_TEMPERATURE] == 24
|
||||
assert state.attributes['drlc_status_duration'] == 0
|
||||
assert state.attributes['drlc_status_level'] == -1
|
||||
assert state.attributes['drlc_status_start'] == '1970-01-01T00:00:00Z'
|
||||
assert state.attributes['drlc_status_override'] is False
|
||||
assert state.attributes['power_consumption_start'] == \
|
||||
'2019-02-24T21:03:04Z'
|
||||
assert state.attributes['power_consumption_power'] == 0
|
||||
assert state.attributes['power_consumption_energy'] == 500
|
||||
assert state.attributes['power_consumption_end'] == '2019-02-26T02:05:55Z'
|
||||
|
||||
|
||||
async def test_set_fan_mode(hass, thermostat, air_conditioner):
|
||||
"""Test the fan mode is set successfully."""
|
||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[thermostat])
|
||||
await setup_platform(hass, CLIMATE_DOMAIN,
|
||||
devices=[thermostat, air_conditioner])
|
||||
entity_ids = ['climate.thermostat', 'climate.air_conditioner']
|
||||
await hass.services.async_call(
|
||||
CLIMATE_DOMAIN, SERVICE_SET_FAN_MODE, {
|
||||
ATTR_ENTITY_ID: 'climate.thermostat',
|
||||
ATTR_ENTITY_ID: entity_ids,
|
||||
ATTR_FAN_MODE: 'auto'},
|
||||
blocking=True)
|
||||
state = hass.states.get('climate.thermostat')
|
||||
assert state.attributes[ATTR_FAN_MODE] == 'auto'
|
||||
for entity_id in entity_ids:
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.attributes[ATTR_FAN_MODE] == 'auto', entity_id
|
||||
|
||||
|
||||
async def test_set_operation_mode(hass, thermostat):
|
||||
async def test_set_operation_mode(hass, thermostat, air_conditioner):
|
||||
"""Test the operation mode is set successfully."""
|
||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[thermostat])
|
||||
await setup_platform(hass, CLIMATE_DOMAIN,
|
||||
devices=[thermostat, air_conditioner])
|
||||
entity_ids = ['climate.thermostat', 'climate.air_conditioner']
|
||||
await hass.services.async_call(
|
||||
CLIMATE_DOMAIN, SERVICE_SET_OPERATION_MODE, {
|
||||
ATTR_ENTITY_ID: 'climate.thermostat',
|
||||
ATTR_OPERATION_MODE: STATE_ECO},
|
||||
ATTR_ENTITY_ID: entity_ids,
|
||||
ATTR_OPERATION_MODE: STATE_COOL},
|
||||
blocking=True)
|
||||
state = hass.states.get('climate.thermostat')
|
||||
assert state.state == STATE_ECO
|
||||
|
||||
for entity_id in entity_ids:
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_COOL, entity_id
|
||||
|
||||
|
||||
async def test_set_temperature_heat_mode(hass, thermostat):
|
||||
|
@ -262,6 +331,32 @@ async def test_set_temperature(hass, thermostat):
|
|||
assert state.attributes[ATTR_TARGET_TEMP_LOW] == 22.2
|
||||
|
||||
|
||||
async def test_set_temperature_ac(hass, air_conditioner):
|
||||
"""Test the temperature is set successfully."""
|
||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[air_conditioner])
|
||||
await hass.services.async_call(
|
||||
CLIMATE_DOMAIN, SERVICE_SET_TEMPERATURE, {
|
||||
ATTR_ENTITY_ID: 'climate.air_conditioner',
|
||||
ATTR_TEMPERATURE: 27},
|
||||
blocking=True)
|
||||
state = hass.states.get('climate.air_conditioner')
|
||||
assert state.attributes[ATTR_TEMPERATURE] == 27
|
||||
|
||||
|
||||
async def test_set_temperature_ac_with_mode(hass, air_conditioner):
|
||||
"""Test the temperature is set successfully."""
|
||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[air_conditioner])
|
||||
await hass.services.async_call(
|
||||
CLIMATE_DOMAIN, SERVICE_SET_TEMPERATURE, {
|
||||
ATTR_ENTITY_ID: 'climate.air_conditioner',
|
||||
ATTR_TEMPERATURE: 27,
|
||||
ATTR_OPERATION_MODE: STATE_COOL},
|
||||
blocking=True)
|
||||
state = hass.states.get('climate.air_conditioner')
|
||||
assert state.attributes[ATTR_TEMPERATURE] == 27
|
||||
assert state.state == STATE_COOL
|
||||
|
||||
|
||||
async def test_set_temperature_with_mode(hass, thermostat):
|
||||
"""Test the temperature and mode is set successfully."""
|
||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[thermostat])
|
||||
|
@ -278,6 +373,31 @@ async def test_set_temperature_with_mode(hass, thermostat):
|
|||
assert state.state == STATE_AUTO
|
||||
|
||||
|
||||
async def test_set_turn_off(hass, air_conditioner):
|
||||
"""Test the a/c is turned off successfully."""
|
||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[air_conditioner])
|
||||
state = hass.states.get('climate.air_conditioner')
|
||||
assert state.state == STATE_AUTO
|
||||
await hass.services.async_call(
|
||||
CLIMATE_DOMAIN, SERVICE_TURN_OFF,
|
||||
blocking=True)
|
||||
state = hass.states.get('climate.air_conditioner')
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
async def test_set_turn_on(hass, air_conditioner):
|
||||
"""Test the a/c is turned on successfully."""
|
||||
air_conditioner.status.update_attribute_value(Attribute.switch, 'off')
|
||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[air_conditioner])
|
||||
state = hass.states.get('climate.air_conditioner')
|
||||
assert state.state == STATE_OFF
|
||||
await hass.services.async_call(
|
||||
CLIMATE_DOMAIN, SERVICE_TURN_ON,
|
||||
blocking=True)
|
||||
state = hass.states.get('climate.air_conditioner')
|
||||
assert state.state == STATE_AUTO
|
||||
|
||||
|
||||
async def test_entity_and_device_attributes(hass, thermostat):
|
||||
"""Test the attributes of the entries are correct."""
|
||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[thermostat])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue