How to use pysmartthings - 10 common examples

To help you get started, we’ve selected a few pysmartthings examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github andrewsayre / pysmartthings / tests / test_device.py View on Github external
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'
github andrewsayre / pysmartthings / tests / test_app.py View on Github external
def test_init():
        """Tests the init function."""
        # Arrange/Act
        app = App()
        # Assert
        assert app.classifications is not None
        assert app.lambda_functions is not None
github andrewsayre / pysmartthings / tests / test_subscription.py View on Github external
def test_init():
        """Test the initialization method."""
        # Arrange/Act
        sub = Subscription()
        # Assert
        assert sub.source_type is SourceType.UNKNOWN
        assert sub.capability == '*'
        assert sub.attribute == '*'
        assert sub.value == '*'
        assert sub.state_change_only
github andrewsayre / pysmartthings / tests / test_subscription.py View on Github external
def test_init():
        """Test the initialization method."""
        # Arrange/Act
        sub = Subscription()
        # Assert
        assert sub.source_type is SourceType.UNKNOWN
        assert sub.capability == '*'
        assert sub.attribute == '*'
        assert sub.value == '*'
        assert sub.state_change_only
github andrewsayre / pysmartthings / tests / test_app.py View on Github external
def test_init():
        """Tests the initialization."""
        # Arrange
        app_id = '5c03e518-118a-44cb-85ad-7877d0b302e4'
        # Act
        oauth = AppOAuth(app_id)
        # Assert
        assert app_id == oauth.app_id
        assert oauth.scope is not None
github andrewsayre / pysmartthings / tests / test_device.py View on Github external
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 == '%'
github home-assistant / home-assistant / tests / components / smartthings / test_sensor.py View on Github external
async def test_entity_state(hass, device_factory):
    """Tests the state attributes properly match the sensor types."""
    device = device_factory("Sensor 1", [Capability.battery], {Attribute.battery: 100})
    await setup_platform(hass, SENSOR_DOMAIN, devices=[device])
    state = hass.states.get("sensor.sensor_1_battery")
    assert state.state == "100"
    assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == "%"
    assert state.attributes[ATTR_FRIENDLY_NAME] == device.label + " Battery"
github home-assistant / home-assistant / tests / components / smartthings / test_switch.py View on Github external
async def test_unload_config_entry(hass, device_factory):
    """Test the switch is removed when the config entry is unloaded."""
    # Arrange
    device = device_factory("Switch 1", [Capability.switch], {Attribute.switch: "on"})
    config_entry = await setup_platform(hass, SWITCH_DOMAIN, devices=[device])
    # Act
    await hass.config_entries.async_forward_entry_unload(config_entry, "switch")
    # Assert
    assert not hass.states.get("switch.switch_1")
github home-assistant / home-assistant / tests / components / smartthings / test_climate.py View on Github external
def legacy_thermostat_fixture(device_factory):
    """Fixture returns a legacy thermostat."""
    device = device_factory(
        "Legacy Thermostat",
        capabilities=[Capability.thermostat],
        status={
            Attribute.cooling_setpoint: 74,
            Attribute.heating_setpoint: 68,
            Attribute.thermostat_fan_mode: "auto",
            Attribute.supported_thermostat_fan_modes: ["auto", "on"],
            Attribute.thermostat_mode: "auto",
            Attribute.supported_thermostat_modes: climate.MODE_TO_STATE.keys(),
            Attribute.thermostat_operating_state: "idle",
        },
    )
    device.status.attributes[Attribute.temperature] = Status(70, "F", None)
    return device
github andrewsayre / pysmartthings / tests / test_device.py View on Github external
async def test_set_thermostat_mode(api):
        """Tests the set_thermostat_mode method."""
        # Arrange
        device = DeviceEntity(api, device_id=DEVICE_ID)
        device.capabilities.append(Capability.thermostat_mode)
        device.status.thermostat_mode = 'heat'
        # Act
        result = await device.set_thermostat_mode('auto')
        # Assert
        assert result
        assert device.status.thermostat_mode != 'auto'