Ejemplo n.º 1
0
def retrievable_device() -> Other:
    result = Other(
        device_id='device1',
        device_name='Test',
        capabilities=[Toggle(instance=Toggle.Instance.Backlight,
                             retrievable=True
                             )]
    )

    return result
Ejemplo n.º 2
0
def retrievable_device() -> Other:
    result = Other(device_id='device1',
                   device_name='Test',
                   capabilities=[
                       Range(instance=Range.Instance.Humidity,
                             unit=Range.Unit.Percent,
                             min_value=50.,
                             max_value=100.,
                             retrievable=True)
                   ])
    return result
def no_color_device() -> Other:
    result = Other(
        device_id='device3',
        device_name='Test',
        capabilities=[ColorSetting(
            temperature=ColorSetting.Temperature(value=5000),
            retrievable=True,
        )],
    )

    return result
def no_temperature_device() -> Other:
    result = Other(
        device_id='device2',
        device_name='Test',
        capabilities=[ColorSetting(
            color_model=ColorSetting.HSV(h=1, s=2, v=3),
            retrievable=True,
        )],
    )

    return result
Ejemplo n.º 5
0
def retrievable_device() -> Other:
    result = Other(
        device_id='device1',
        device_name='Test',
        capabilities=[Mode(instance=Mode.Instance.CleanupMode,
                           modes=(Mode.WorkMode.Americano, Mode.WorkMode.FanOnly),
                           initial_value=Mode.WorkMode.Americano,
                           retrievable=True
                           )]
    )

    return result
Ejemplo n.º 6
0
def device() -> Other:
    return Other(
        device_id='device1',
        device_name='Test',
        capabilities=[],
        properties=[
            Amperage(initial_value=10.),
            CO2Level(initial_value=800.),
            Humidity(initial_value=85.),
            Power(initial_value=0.),
            Temperature(unit=Temperature.Unit.Celsius, initial_value=42),
            Voltage(initial_value=12.),
            WaterLevel(initial_value=100),
        ]
    )
Ejemplo n.º 7
0
async def test_state(retrievable_device: Other):
    next(iter(retrievable_device.capabilities())).value = 60.

    state = await retrievable_device.state()
    expected = {
        'id':
        'device1',
        'capabilities': [{
            'type': 'devices.capabilities.range',
            'state': {
                'instance': 'humidity',
                'value': 60.,
            },
        }],
        'properties': [],
    }
    assert state == expected
Ejemplo n.º 8
0
async def test_state(retrievable_device: Other):
    next(iter(retrievable_device.capabilities())).value = 'fan_only'

    state = await retrievable_device.state()
    expected = {
        'id': 'device1',
        'capabilities': [
            {
                'type': 'devices.capabilities.mode',
                'state': {
                    'instance': 'cleanup_mode',
                    'value': 'fan_only',
                },
            }
        ],
        'properties': [],
    }
    assert state == expected
Ejemplo n.º 9
0
async def test_state(retrievable_device: Other):
    next(iter(retrievable_device.capabilities())).value = True

    state = await retrievable_device.state()
    expected = {
        'id': 'device1',
        'capabilities': [
            {
                'type': 'devices.capabilities.toggle',
                'state': {
                    'instance': 'backlight',
                    'value': True,
                },
            }
        ],
        'properties': [],
    }
    assert state == expected
Ejemplo n.º 10
0
async def test_action(retrievable_device: Other):
    result = await retrievable_device.action([{
        'type': 'devices.capabilities.mode',
        'state': {
            'instance': 'unknown',
            'value': 'americano',
        }
    }], None)
    expected = {
        'id': 'device1',
        'capabilities': [
            {
                'type': 'devices.capabilities.mode',
                'state': {
                    'instance': 'unknown',
                    'action_result': {
                        'status': 'ERROR',
                        'error_code': 'INVALID_ACTION',
                        'error_message': 'Unknown capability for this device',
                    }
                }
            }
        ]
    }
    assert result == expected

    result = await retrievable_device.action([{
        'type': 'devices.capabilities.mode',
        'state': {
            'instance': 'cleanup_mode',
            'value': 'americano',
        }
    }], None)
    expected = {
        'id': 'device1',
        'capabilities': [
            {
                'type': 'devices.capabilities.mode',
                'state': {
                    'instance': 'cleanup_mode',
                    'action_result': {
                        'status': 'ERROR',
                        'error_code': 'NOT_SUPPORTED_IN_CURRENT_MODE',
                        'error_message': 'NOT_SUPPORTED_IN_CURRENT_MODE',
                    }
                }
            }
        ]
    }
    assert result == expected

    async def change_value(capability, instance, value):
        capability.value = value
        return capability.type_id, instance

    next(iter(retrievable_device.capabilities())).change_value = change_value
    result = await retrievable_device.action([{
        'type': 'devices.capabilities.mode',
        'state': {
            'instance': 'cleanup_mode',
            'value': 'fan_only',
        }
    }], None)
    expected = {
        'id': 'device1',
        'capabilities': [
            {
                'type': 'devices.capabilities.mode',
                'state': {
                    'instance': 'cleanup_mode',
                    'action_result': {
                        'status': 'DONE',
                    }
                }
            }
        ]
    }
    assert result == expected
    assert next(iter(retrievable_device.capabilities())).value == Mode.WorkMode.FanOnly.value
Ejemplo n.º 11
0
async def test_action(device: Other):
    result = await device.action([{
        'type': 'devices.capabilities.color_setting',
        'state': {
            'instance': 'unknown',
            'value': False,
        }
    }], None)
    expected = {
        'id': 'device1',
        'capabilities': [
            {
                'type': 'devices.capabilities.color_setting',
                'state': {
                    'instance': 'unknown',
                    'action_result': {
                        'status': 'ERROR',
                        'error_code': 'INVALID_ACTION',
                        'error_message': 'Unknown capability for this device',
                    }
                }
            }
        ],
    }
    assert result == expected

    result = await device.action([{
        'type': 'devices.capabilities.color_setting',
        'state': {
            'instance': 'temperature_k',
            'value': False,
        }
    }], None)
    expected = {
        'id': 'device1',
        'capabilities': [
            {
                'type': 'devices.capabilities.color_setting',
                'state': {
                    'instance': 'temperature_k',
                    'action_result': {
                        'status': 'ERROR',
                        'error_code': 'NOT_SUPPORTED_IN_CURRENT_MODE',
                        'error_message': 'NOT_SUPPORTED_IN_CURRENT_MODE',
                    }
                }
            }
        ],
    }
    assert result == expected

    async def change_value(capability, instance, value):
        if capability.value is not None and instance == capability.value.name:
            capability.value.assign(value)
        elif instance not in capability.instances:
            raise TypeError(f"Instance type {instance} is not supported for capability")
        else:
            if instance == capability.temperature.name:
                newval = capability.temperature
            else:
                newval = capability.color_model
            newval.assign(value)
            capability.value = newval

        return capability.type_id, instance

    next(iter(device.capabilities())).change_value = change_value
    result = await device.action([{
        'type': 'devices.capabilities.color_setting',
        'state': {
            'instance': 'temperature_k',
            'value': 6000,
        }
    }], None)
    expected = {
        'id': 'device1',
        'capabilities': [
            {
                'type': 'devices.capabilities.color_setting',
                'state': {
                    'instance': 'temperature_k',
                    'action_result': {
                        'status': 'DONE',
                    }
                }
            }
        ]
    }
    assert result == expected

    expected_state = {
        'id': 'device1',
        'capabilities': [
            {
                'type': 'devices.capabilities.color_setting',
                'state': {
                    'instance': 'temperature_k',
                    'value': 6000,
                }
            }
        ],
        'properties': [],
    }

    assert await device.state() == expected_state