Skip to content

Commit 7f65b29

Browse files
committed
Add well-known attributes methods ofr airConditionerMode, airConditionerFanMode, and airFlowDirection
1 parent 1435157 commit 7f65b29

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

pysmartthings/device.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,32 @@ def air_conditioner_mode(self) -> Optional[str]:
541541
"""Get the air conditioner mode attribute."""
542542
return self._attributes[Attribute.air_conditioner_mode].value
543543

544+
@property
545+
def supported_ac_modes(self) -> Sequence[str]:
546+
"""Get the supported AC modes attribute."""
547+
value = self._attributes[Attribute.supported_ac_modes].value
548+
if isinstance(value, Sequence):
549+
return sorted(value)
550+
return []
551+
552+
@property
553+
def fan_mode(self) -> Optional[str]:
554+
"""Get the fan mode attribute."""
555+
return self._attributes[Attribute.fan_mode].value
556+
557+
@property
558+
def supported_ac_fan_modes(self) -> Sequence[str]:
559+
"""Get the supported AC fan modes attribute."""
560+
value = self._attributes[Attribute.supported_ac_fan_modes].value
561+
if isinstance(value, Sequence):
562+
return sorted(value)
563+
return []
564+
565+
@property
566+
def air_flow_direction(self) -> str:
567+
"""Get the airFlowDirection attribute."""
568+
return self._attributes[Attribute.air_flow_direction].value
569+
544570
@property
545571
def three_axis(self) -> Optional[Tuple[int, int, int]]:
546572
"""Get the three axis attribute."""
@@ -935,6 +961,28 @@ async def set_air_conditioner_mode(
935961
Attribute.air_conditioner_mode, mode)
936962
return result
937963

964+
async def set_fan_mode(self, mode: str, *, set_status: bool = False,
965+
component_id: str = 'main'):
966+
"""Call the setFanMode command."""
967+
result = await self.command(
968+
component_id, Capability.air_conditioner_fan_mode,
969+
Command.set_fan_mode, [mode])
970+
if result and set_status:
971+
self.status.update_attribute_value(Attribute.fan_mode, mode)
972+
return result
973+
974+
async def set_air_flow_direction(
975+
self, direction: str, *, set_status: bool = False,
976+
component_id: str = 'main'):
977+
"""Call the setAirFlowDirection command."""
978+
result = await self.command(
979+
component_id, Capability.air_flow_direction,
980+
Command.set_air_flow_direction, [direction])
981+
if result and set_status:
982+
self.status.update_attribute_value(
983+
Attribute.air_flow_direction, direction)
984+
return result
985+
938986
@property
939987
def status(self):
940988
"""Get the status entity of the device."""
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"commands": [
3+
{
4+
"component": "main",
5+
"capability": "airFlowDirection",
6+
"command": "setAirFlowDirection",
7+
"arguments": ["fixed"]
8+
}
9+
]
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"commands": [
3+
{
4+
"component": "main",
5+
"capability": "airConditionerFanMode",
6+
"command": "setFanMode",
7+
"arguments": ["auto"]
8+
}
9+
]
10+
}

tests/test_device.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,30 @@ async def test_set_air_conditioner_mode(api):
771771
assert await device.set_air_conditioner_mode('auto', set_status=True)
772772
assert device.status.air_conditioner_mode == 'auto'
773773

774+
@staticmethod
775+
@pytest.mark.asyncio
776+
async def test_set_fan_mode(api):
777+
"""Tests the set_fan_mode method."""
778+
# Arrange
779+
device = DeviceEntity(api, device_id=DEVICE_ID)
780+
# Act/Assert
781+
assert await device.set_fan_mode('auto')
782+
assert device.status.fan_mode is None
783+
assert await device.set_fan_mode('auto', set_status=True)
784+
assert device.status.fan_mode == 'auto'
785+
786+
@staticmethod
787+
@pytest.mark.asyncio
788+
async def test_set_air_flow_direction(api):
789+
"""Tests the set_air_flow_direction method."""
790+
# Arrange
791+
device = DeviceEntity(api, device_id=DEVICE_ID)
792+
# Act/Assert
793+
assert await device.set_air_flow_direction('fixed')
794+
assert device.status.air_flow_direction is None
795+
assert await device.set_air_flow_direction('fixed', set_status=True)
796+
assert device.status.air_flow_direction == 'fixed'
797+
774798

775799
class TestDeviceStatus:
776800
"""Tests for the DeviceStatus class."""
@@ -1015,6 +1039,10 @@ def test_well_known_attributes():
10151039
"""Tests the humidity property."""
10161040
# Arrange
10171041
status = DeviceStatus(None, device_id=DEVICE_ID)
1042+
1043+
assert status.supported_ac_modes == []
1044+
assert status.supported_ac_fan_modes == []
1045+
10181046
status.update_attribute_value(Attribute.humidity, 50)
10191047
status.update_attribute_value(Attribute.temperature, 55)
10201048
status.update_attribute_value(
@@ -1028,6 +1056,11 @@ def test_well_known_attributes():
10281056
status.update_attribute_value(Attribute.window_shade, 'closed')
10291057
status.update_attribute_value(Attribute.data, {'test': 'test'})
10301058
status.update_attribute_value(Attribute.three_axis, [0, 0, 0])
1059+
status.update_attribute_value(
1060+
Attribute.supported_ac_modes, ['auto', 'cool'])
1061+
status.update_attribute_value(Attribute.fan_mode, 'low')
1062+
status.update_attribute_value(
1063+
Attribute.supported_ac_fan_modes, ['auto', 'low'])
10311064
# Act/Assert
10321065
assert status.humidity == 50
10331066
assert status.temperature == 55
@@ -1039,6 +1072,8 @@ def test_well_known_attributes():
10391072
assert status.window_shade == 'closed'
10401073
assert status.data == {'test': 'test'}
10411074
assert status.three_axis == [0, 0, 0]
1075+
assert status.supported_ac_modes == ['auto', 'cool']
1076+
assert status.supported_ac_fan_modes == ['auto', 'low']
10421077

10431078
@staticmethod
10441079
def test_well_known_ocf_attributes():

0 commit comments

Comments
 (0)