Exemple #1
0
 def test_fan_speed_range():
     """Tests the fan_speed property's range."""
     # Arrange
     status = DeviceStatus(None, device_id=DEVICE_ID)
     # Act/Assert
     with pytest.raises(ValueError):
         status.fan_speed = -1
Exemple #2
0
 def test_switch():
     """Tests the switch property."""
     # Arrange
     status = DeviceStatus(None, device_id=DEVICE_ID)
     # Act
     status.switch = True
     # Assert
     assert status.switch
Exemple #3
0
 def test_level():
     """Tests the level property."""
     # Arrange
     status = DeviceStatus(None, device_id=DEVICE_ID)
     # Act
     status.level = 50
     # Assert
     assert status.level == 50
Exemple #4
0
 def test_fan_speed():
     """Tests the fan_speed property."""
     # Arrange
     status = DeviceStatus(None, device_id=DEVICE_ID)
     # Act
     status.fan_speed = 50
     # Assert
     assert status.fan_speed == 50
Exemple #5
0
 def test_color_format():
     """Tests the color property's validation."""
     # Arrange
     status = DeviceStatus(None, device_id=DEVICE_ID)
     # Act/Assert
     values = ['000000', '#00000', '#HH2000']
     for value in values:
         with pytest.raises(ValueError):
             status.color = value
Exemple #6
0
 def test_color_temperature_range():
     """Tests the hue property's range."""
     # Arrange
     status = DeviceStatus(None, device_id=DEVICE_ID)
     # Act/Assert
     values = [0, 30001]
     for value in values:
         with pytest.raises(ValueError):
             status.color_temperature = value
Exemple #7
0
 def test_saturation_range():
     """Tests the hue property's range."""
     # Arrange
     status = DeviceStatus(None, device_id=DEVICE_ID)
     # Act/Assert
     values = [-1, 101]
     for value in values:
         with pytest.raises(ValueError):
             status.saturation = value
Exemple #8
0
 def test_apply_attribute_update_child_status():
     """Tests the apply_attribute_update method to a child status."""
     # Arrange
     data = get_json('device_status.json')
     status = DeviceStatus(None, DEVICE_ID, data)
     # Act
     status.apply_attribute_update(
         'bottomButton', 'switchLevel', 'level', 50)
     # Assert
     assert status.components['bottomButton'].level == 50
Exemple #9
0
 def test_apply_attribute_update_preserve_unit():
     """Tests the apply_attribute_update preserves the old unit."""
     # Arrange
     data = get_json('device_status.json')
     device = DeviceStatus(None, DEVICE_ID, data)
     device.attributes[Capability.switch_level] = Status(40, '%', None)
     # Act
     device.apply_attribute_update(
         'main', Capability.switch_level, Attribute.level, 50)
     # Assert
     status = device.attributes[Attribute.level]
     assert status.unit == '%'
Exemple #10
0
 def test_apply_attribute_update():
     """Tests the apply_attribute_update method."""
     # Arrange
     data = get_json('device_status.json')
     device = DeviceStatus(None, DEVICE_ID, data)
     # Act
     device.apply_attribute_update(
         'main', Capability.switch_level, Attribute.level, 50, '%',
         {'test': 'test'})
     # Assert
     status = device.attributes[Attribute.level]
     assert status.value == 50
     assert status.unit == '%'
     assert status.data == {'test': 'test'}
Exemple #11
0
 def test_well_known_drlc_attributes():
     """Tests the drlc related attributes."""
     status = DeviceStatus(None, device_id=DEVICE_ID)
     # No attribute
     assert status.drlc_status is None
     assert status.drlc_status_duration is None
     assert status.drlc_status_level is None
     assert status.drlc_status_override is None
     assert status.drlc_status_start is None
     # Populated
     drlc_status = {
         "duration": 0,
         "drlcLevel": -1,
         "start": "1970-01-01T00:00:00Z",
         "override": False,
     }
     status.update_attribute_value(Attribute.drlc_status, drlc_status)
     assert status.drlc_status == drlc_status
     assert status.drlc_status_duration == 0
     assert status.drlc_status_level == -1
     assert not status.drlc_status_override
     assert status.drlc_status_start == "1970-01-01T00:00:00Z"
     # Missing
     status.update_attribute_value(Attribute.drlc_status, {})
     assert status.drlc_status == {}
     assert status.drlc_status_duration is None
     assert status.drlc_status_level is None
     assert status.drlc_status_override is None
     assert status.drlc_status_start is None
     # Not valid
     drlc_status = {"duration": "Foo", "drlcLevel": "Foo"}
     status.update_attribute_value(Attribute.drlc_status, drlc_status)
     assert status.drlc_status == drlc_status
     assert status.drlc_status_duration is None
     assert status.drlc_status_level is None
Exemple #12
0
 def test_apply_attribute_update():
     """Tests the apply_attribute_update method."""
     # Arrange
     data = get_json("device_status.json")
     device = DeviceStatus(None, DEVICE_ID, data)
     # Act
     device.apply_attribute_update("main", Capability.switch_level,
                                   Attribute.level, 50, "%",
                                   {"test": "test"})
     # Assert
     status = device.attributes[Attribute.level]
     assert status.value == 50
     assert status.unit == "%"
     assert status.data == {"test": "test"}
Exemple #13
0
 def test_well_known_power_consumption_attributes():
     """Tests the power consumption related attributes."""
     status = DeviceStatus(None, device_id=DEVICE_ID)
     # No attribute
     assert status.power_consumption is None
     assert status.power_consumption_end is None
     assert status.power_consumption_energy is None
     assert status.power_consumption_power is None
     assert status.power_consumption_start is None
     # Populated
     data = {
         "start": "2019-02-24T21:03:04Z",
         "power": 0,
         "energy": 500,
         "end": "2019-02-26T02:05:55Z",
     }
     status.update_attribute_value(Attribute.power_consumption, data)
     assert status.power_consumption == data
     assert status.power_consumption_end == "2019-02-26T02:05:55Z"
     assert status.power_consumption_energy == 500
     assert status.power_consumption_power == 0
     assert status.power_consumption_start == "2019-02-24T21:03:04Z"
     # Missing
     status.update_attribute_value(Attribute.power_consumption, {})
     assert status.power_consumption == {}
     assert status.power_consumption_end is None
     assert status.power_consumption_energy is None
     assert status.power_consumption_power is None
     assert status.power_consumption_start is None
     # Not valid
     data = {"power": "Foo", "energy": "Bar"}
     status.update_attribute_value(Attribute.power_consumption, data)
     assert status.power_consumption == data
     assert status.power_consumption_energy is None
     assert status.power_consumption_power is None
Exemple #14
0
 def test_attributes_default():
     """Test the attributes property."""
     # Arrange
     data = get_json('device_status.json')
     status = DeviceStatus(None, DEVICE_ID, data)
     # Act/Assert
     assert status.attributes['thermostatSetpoint'] == (None, None, None)
Exemple #15
0
 async def test_refresh(api):
     """Tests the refresh method."""
     # Arrange
     status = DeviceStatus(api, device_id=DEVICE_ID)
     # Act
     await status.refresh()
     # Assert
     assert len(status.attributes) == 9
Exemple #16
0
 def test_is_on():
     """Tests the is_on method."""
     # Arrange
     status = DeviceStatus(None, device_id=DEVICE_ID)
     status.update_attribute_value(Attribute.acceleration, 'active')
     status.level = 100
     # Act/Assert
     assert status.is_on(Attribute.acceleration)
     assert status.is_on(Attribute.level)
     assert not status.is_on(Attribute.switch)
Exemple #17
0
 def test_init():
     """Tests the init method."""
     # Arrange/Act
     status = DeviceStatus(None, device_id=DEVICE_ID)
     # Assert
     assert status.device_id == DEVICE_ID
     assert status.attributes == {}
     assert not status.switch
     assert not status.motion
     assert status.level == 0
     assert status.component_id == 'main'
Exemple #18
0
 def test_apply_data():
     """Tests the apply_data method."""
     # Arrange
     data = get_json('device_status.json')
     # Act
     status = DeviceStatus(None, DEVICE_ID, data)
     # Assert
     assert len(status.attributes) == 9
     assert status.switch
     assert status.level == 100
     assert len(status.components) == 2
     assert len(status.components['topButton'].attributes) == 3
     assert len(status.components['bottomButton'].attributes) == 3
Exemple #19
0
 def test_values():
     """Test the values property."""
     # Arrange
     data = get_json("device_status.json")
     status = DeviceStatus(None, DEVICE_ID, data)
     # Act/Assert
     assert status.values == {
         "button": None,
         "numberOfButtons": None,
         "supportedButtonValues": None,
         "indicatorStatus": "when off",
         "switch": "on",
         "checkInterval": 1920,
         "healthStatus": None,
         "DeviceWatch-DeviceStatus": None,
         "level": 100,
     }
Exemple #20
0
 def test_values():
     """Test the values property."""
     # Arrange
     data = get_json('device_status.json')
     status = DeviceStatus(None, DEVICE_ID, data)
     # Act/Assert
     assert status.values == {
         'button': None,
         'numberOfButtons': None,
         'supportedButtonValues': None,
         'indicatorStatus': 'when off',
         'switch': 'on',
         'checkInterval': 1920,
         'healthStatus': None,
         'DeviceWatch-DeviceStatus': None,
         'level': 100
     }
Exemple #21
0
 def test_attributes():
     """Test the attributes property."""
     # Arrange
     data = get_json('device_status.json')
     status = DeviceStatus(None, DEVICE_ID, data)
     # Act/Assert
     assert status.attributes == {
         'button': (None, None, None),
         'numberOfButtons': (None, None, None),
         'supportedButtonValues': (None, None, None),
         'indicatorStatus': ('when off', None, None),
         'switch': ('on', None, None),
         'checkInterval': (1920, 's', {"protocol": "zwave",
                                       "hubHardwareId": "000F"}),
         'healthStatus': (None, None, {}),
         'DeviceWatch-DeviceStatus': (None, None, {}),
         'level': (100, '%', None)
     }
Exemple #22
0
 def test_well_known_ocf_attributes():
     """Tests the OCF related attributes."""
     # Arrange
     data = get_json('device_samsungac_status.json')
     status = DeviceStatus(None, device_id=DEVICE_ID, data=data)
     # Act/Assert
     assert status.ocf_data_model_version == 'res.1.1.0,sh.1.1.0'
     assert status.ocf_date_of_manufacture == '2019-02-26T02:05:55Z'
     assert status.ocf_device_id == DEVICE_ID
     assert status.ocf_firmware_version == '0.1.0'
     assert status.ocf_hardware_version == '1.0'
     assert status.ocf_manufacturer_details_link == 'http://www.samsung.com'
     assert status.ocf_manufacturer_name == 'Samsung Electronics'
     assert status.ocf_model_number == \
         'ARTIK051_KRAC_18K|10193441|60010123001111010200000000000000'
     assert status.ocf_name == 'Air Conditioner'
     assert status.ocf_os_version == 'TizenRT2.0'
     assert status.ocf_platform_id == 'd5226d90-1b4f-e59d-5f3f-027ac3b18faf'
     assert status.ocf_platform_version == '0.1.0'
     assert status.ocf_spec_version == 'core.1.1.0'
     assert status.ocf_support_link == 'http://www.samsung.com/support'
     assert status.ocf_system_time == '02:05:55Z'
     assert status.ocf_vendor_id == 'DA-AC-RAC-000001'
Exemple #23
0
 def test_attributes():
     """Test the attributes property."""
     # Arrange
     data = get_json("device_status.json")
     status = DeviceStatus(None, DEVICE_ID, data)
     # Act/Assert
     assert status.attributes == {
         "button": (None, None, None),
         "numberOfButtons": (None, None, None),
         "supportedButtonValues": (None, None, None),
         "indicatorStatus": ("when off", None, None),
         "switch": ("on", None, None),
         "checkInterval": (
             1920,
             "s",
             {
                 "protocol": "zwave",
                 "hubHardwareId": "000F"
             },
         ),
         "healthStatus": (None, None, {}),
         "DeviceWatch-DeviceStatus": (None, None, {}),
         "level": (100, "%", None),
     }
Exemple #24
0
    def test_well_known_attributes():
        """Tests the humidity property."""
        # Arrange
        status = DeviceStatus(None, device_id=DEVICE_ID)

        assert status.supported_ac_modes == []
        assert status.supported_ac_fan_modes == []

        status.update_attribute_value(Attribute.humidity, 50)
        status.update_attribute_value(Attribute.temperature, 55)
        status.update_attribute_value(Attribute.thermostat_operating_state,
                                      "on")
        status.update_attribute_value(Attribute.supported_thermostat_fan_modes,
                                      ["on", "off"])
        status.update_attribute_value(Attribute.supported_thermostat_modes,
                                      ["auto", "off"])
        status.update_attribute_value(Attribute.lock, "locked")
        status.update_attribute_value(Attribute.door, "open")
        status.update_attribute_value(Attribute.window_shade, "closed")
        status.update_attribute_value(Attribute.data, {"test": "test"})
        status.update_attribute_value(Attribute.three_axis, [0, 0, 0])
        status.update_attribute_value(Attribute.supported_ac_modes,
                                      ["auto", "cool"])
        status.update_attribute_value(Attribute.fan_mode, "low")
        status.update_attribute_value(Attribute.supported_ac_fan_modes,
                                      ["auto", "low"])
        # Act/Assert
        assert status.humidity == 50
        assert status.temperature == 55
        assert status.thermostat_operating_state == "on"
        assert status.supported_thermostat_fan_modes == ["on", "off"]
        assert status.supported_thermostat_modes == ["auto", "off"]
        assert status.lock == "locked"
        assert status.door == "open"
        assert status.window_shade == "closed"
        assert status.data == {"test": "test"}
        assert status.three_axis == [0, 0, 0]
        assert status.supported_ac_modes == ["auto", "cool"]
        assert status.supported_ac_fan_modes == ["auto", "low"]
Exemple #25
0
    def test_well_known_attributes():
        """Tests the humidity property."""
        # Arrange
        status = DeviceStatus(None, device_id=DEVICE_ID)

        assert status.supported_ac_modes == []
        assert status.supported_ac_fan_modes == []

        status.update_attribute_value(Attribute.humidity, 50)
        status.update_attribute_value(Attribute.temperature, 55)
        status.update_attribute_value(
            Attribute.thermostat_operating_state, 'on')
        status.update_attribute_value(
            Attribute.supported_thermostat_fan_modes, ['on', 'off'])
        status.update_attribute_value(
            Attribute.supported_thermostat_modes, ['auto', 'off'])
        status.update_attribute_value(Attribute.lock, 'locked')
        status.update_attribute_value(Attribute.door, 'open')
        status.update_attribute_value(Attribute.window_shade, 'closed')
        status.update_attribute_value(Attribute.data, {'test': 'test'})
        status.update_attribute_value(Attribute.three_axis, [0, 0, 0])
        status.update_attribute_value(
            Attribute.supported_ac_modes, ['auto', 'cool'])
        status.update_attribute_value(Attribute.fan_mode, 'low')
        status.update_attribute_value(
            Attribute.supported_ac_fan_modes, ['auto', 'low'])
        # Act/Assert
        assert status.humidity == 50
        assert status.temperature == 55
        assert status.thermostat_operating_state == 'on'
        assert status.supported_thermostat_fan_modes == ['on', 'off']
        assert status.supported_thermostat_modes == ['auto', 'off']
        assert status.lock == 'locked'
        assert status.door == 'open'
        assert status.window_shade == 'closed'
        assert status.data == {'test': 'test'}
        assert status.three_axis == [0, 0, 0]
        assert status.supported_ac_modes == ['auto', 'cool']
        assert status.supported_ac_fan_modes == ['auto', 'low']