コード例 #1
0
ファイル: lighthub.py プロジェクト: darookee/hass-config
def handle_light_toggle(hass, service):
    target_ids = service.data[ATTR_ENTITY_ID]
    for target_id in target_ids:
        if core.is_on(hass, target_id):
            core.turn_off(hass, target_id)
        else:
            core.turn_on(hass, target_id)
コード例 #2
0
def all_lights_off(hass, entity_id, old_state, new_state):
    """If all lights turn off, turn off."""
    if not TARGET_ID:
        return

    if core.is_on(hass, TARGET_ID):
        _LOGGER.info('All lights have been turned off, turning it off')
        core.turn_off(hass, TARGET_ID)
コード例 #3
0
ファイル: test_init.py プロジェクト: cellerich/home-assistant
    def test_turn_off(self):
        """Test turn_off method."""
        runs = []
        self.hass.services.register("light", SERVICE_TURN_OFF, lambda x: runs.append(1))

        comps.turn_off(self.hass, "light.Bowl")

        self.hass.pool.block_till_done()

        self.assertEqual(1, len(runs))
コード例 #4
0
ファイル: test_init.py プロジェクト: yuetianle/home-assistant
    def test_turn_off(self):
        """ Test turn_off method. """
        runs = []
        self.hass.services.register('light', SERVICE_TURN_OFF,
                                    lambda x: runs.append(1))

        comps.turn_off(self.hass, 'light.Bowl')

        self.hass.pool.block_till_done()

        self.assertEqual(1, len(runs))
コード例 #5
0
ファイル: example.py プロジェクト: wdn/home-assistant
    def track_devices(entity_id, old_state, new_state):
        """ Called when the group.all devices change state. """

        # If anyone comes home and the core is not on, turn it on.
        if new_state.state == STATE_HOME and not core.is_on(hass, target_id):

            core.turn_on(hass, target_id)

        # If all people leave the house and the core is on, turn it off
        elif new_state.state == STATE_NOT_HOME and core.is_on(hass, target_id):

            core.turn_off(hass, target_id)
コード例 #6
0
ファイル: example.py プロジェクト: gema-arta/home-assistant
    def track_devices(entity_id, old_state, new_state):
        """ Called when the group.all devices change state. """

        # If anyone comes home and the core is not on, turn it on.
        if new_state.state == STATE_HOME and not core.is_on(hass, target_id):

            core.turn_on(hass, target_id)

        # If all people leave the house and the core is on, turn it off
        elif new_state.state == STATE_NOT_HOME and core.is_on(hass, target_id):

            core.turn_off(hass, target_id)
コード例 #7
0
def track_devices(hass, entity_id, old_state, new_state):
    """Called when the group.all devices change state."""
    # If the target id is not set, return
    if not TARGET_ID:
        return

    # If anyone comes home and the entity is not on, turn it on.
    if new_state.state == STATE_HOME and not core.is_on(hass, TARGET_ID):

        core.turn_on(hass, TARGET_ID)

    # If all people leave the house and the entity is on, turn it off.
    elif new_state.state == STATE_NOT_HOME and core.is_on(hass, TARGET_ID):

        core.turn_off(hass, TARGET_ID)
コード例 #8
0
ファイル: example.py プロジェクト: wdn/home-assistant
    def flash_service(call):
        """ Service that will turn the target off for 10 seconds
            if on and vice versa. """

        if core.is_on(hass, target_id):
            core.turn_off(hass, target_id)

            time.sleep(10)

            core.turn_on(hass, target_id)

        else:
            core.turn_on(hass, target_id)

            time.sleep(10)

            core.turn_off(hass, target_id)
コード例 #9
0
ファイル: example.py プロジェクト: gema-arta/home-assistant
    def flash_service(call):
        """ Service that will turn the target off for 10 seconds
            if on and vice versa. """

        if core.is_on(hass, target_id):
            core.turn_off(hass, target_id)

            time.sleep(10)

            core.turn_on(hass, target_id)

        else:
            core.turn_on(hass, target_id)

            time.sleep(10)

            core.turn_off(hass, target_id)
コード例 #10
0
    def update(self):
        """ Update current thermostat. """
        heater = self.hass.states.get(self.heater_entity_id)
        if heater is None:
            self.logger.error("No heater available")
            return

        current_temperature = self.current_temperature
        if current_temperature is None:
            self.logger.error("No temperature available")
            return

        if (current_temperature - self.target_temperature) > \
                TOL_TEMP and heater.state is STATE_ON:
            self._heater_manual_changed = False
            core.turn_off(self.hass, self.heater_entity_id)
        elif (self.target_temperature - self.current_temperature) > TOL_TEMP \
                and heater.state is STATE_OFF:
            self._heater_manual_changed = False
            core.turn_on(self.hass, self.heater_entity_id)
コード例 #11
0
ファイル: example.py プロジェクト: t30/home-assistant
def flash_service(hass, call):
    """
    Service that will turn the target off for 10 seconds if on and vice versa.
    """
    if not TARGET_ID:
        return

    if core.is_on(hass, TARGET_ID):
        core.turn_off(hass, TARGET_ID)

        time.sleep(10)

        core.turn_on(hass, TARGET_ID)

    else:
        core.turn_on(hass, TARGET_ID)

        time.sleep(10)

        core.turn_off(hass, TARGET_ID)
コード例 #12
0
ファイル: example.py プロジェクト: FanaHOVA/home-assistant
def flash_service(hass, call):
    """
    Service that will turn the target off for 10 seconds if on and vice versa.
    """
    if not TARGET_ID:
        return

    if core.is_on(hass, TARGET_ID):
        core.turn_off(hass, TARGET_ID)

        time.sleep(10)

        core.turn_on(hass, TARGET_ID)

    else:
        core.turn_on(hass, TARGET_ID)

        time.sleep(10)

        core.turn_off(hass, TARGET_ID)
コード例 #13
0
ファイル: test_init.py プロジェクト: sara0871/-.gitignore-
 def test_turn_off(self):
     """Test turn_off method."""
     calls = mock_service(self.hass, 'light', SERVICE_TURN_OFF)
     comps.turn_off(self.hass, 'light.Bowl')
     self.hass.block_till_done()
     self.assertEqual(1, len(calls))
コード例 #14
0
ファイル: test_init.py プロジェクト: simpss/home-assistant
 def test_turn_off(self):
     """Test turn_off method."""
     calls = mock_service(self.hass, 'light', SERVICE_TURN_OFF)
     comps.turn_off(self.hass, 'light.Bowl')
     self.hass.block_till_done()
     self.assertEqual(1, len(calls))
コード例 #15
0
ファイル: lighthub.py プロジェクト: darookee/hass-config
def change_brightness(hass, service, bri):
    for target_id in service.data[ATTR_ENTITY_ID]:
        if bri <= 0:
            core.turn_off(hass, target_id)
        elif bri <= 255:
            core.turn_on(hass, target_id, brightness=bri)
コード例 #16
0
ファイル: example.py プロジェクト: wdn/home-assistant
    def all_lights_off(entity_id, old_state, new_state):
        """ If all lights turn off, turn off. """

        if core.is_on(hass, target_id):
            _LOGGER.info('All lights have been turned off, turning it off')
            core.turn_off(hass, target_id)
コード例 #17
0
ファイル: example.py プロジェクト: gema-arta/home-assistant
    def all_lights_off(entity_id, old_state, new_state):
        """ If all lights turn off, turn off. """

        if core.is_on(hass, target_id):
            _LOGGER.info('All lights have been turned off, turning it off')
            core.turn_off(hass, target_id)