当前位置: 首页>>代码示例>>Python>>正文


Python config_validation.entity_id方法代码示例

本文整理汇总了Python中homeassistant.helpers.config_validation.entity_id方法的典型用法代码示例。如果您正苦于以下问题:Python config_validation.entity_id方法的具体用法?Python config_validation.entity_id怎么用?Python config_validation.entity_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在homeassistant.helpers.config_validation的用法示例。


在下文中一共展示了config_validation.entity_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: entity_id_to_number

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import entity_id [as 别名]
def entity_id_to_number(self, entity_id):
        """Get a unique number for the entity id."""
        if self.type == TYPE_ALEXA:
            return entity_id

        if self.numbers is None:
            self.numbers = _load_json(self.hass.config.path(NUMBERS_FILE))

        # Google Home
        for number, ent_id in self.numbers.items():
            if entity_id == ent_id:
                return number

        number = '1'
        if self.numbers:
            number = str(max(int(k) for k in self.numbers) + 1)
        self.numbers[number] = entity_id
        save_json(self.hass.config.path(NUMBERS_FILE), self.numbers)
        return number 
开发者ID:charleyzhu,项目名称:HomeAssistant_Components,代码行数:21,代码来源:__init__.py

示例2: websocket_library

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import entity_id [as 别名]
def websocket_library(hass, connection, msg):
    camera = _get_camera_from_entity_id(hass, msg['entity_id'])
    videos = []
    _LOGGER.debug('library+' + str(msg['at_most']))
    for v in camera.last_n_videos(msg['at_most']):
        videos.append({
            'created_at': v.created_at,
            'created_at_pretty': v.created_at_pretty(camera.last_capture_date_format),
            'url': v.video_url,
            'url_type': v.content_type,
            'thumbnail': v.thumbnail_url,
            'thumbnail_type': 'image/jpeg',
            'object': v.object_type,
            'object_region': v.object_region,
            'trigger': v.object_type,
            'trigger_region': v.object_region,
        })
    connection.send_message(websocket_api.result_message(
        msg['id'], {
            'videos': videos,
        }
    )) 
开发者ID:pschmitt,项目名称:hass-config,代码行数:24,代码来源:camera.py

示例3: websocket_snapshot_image

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import entity_id [as 别名]
def websocket_snapshot_image(hass, connection, msg):
    camera = _get_camera_from_entity_id(hass, msg['entity_id'])
    _LOGGER.debug('snapshot_image for ' + str(camera.unique_id))

    try:
        image = await camera.async_get_snapshot()
        connection.send_message(websocket_api.result_message(
            msg['id'], {
                'content_type': camera.content_type,
                'content': base64.b64encode(image).decode('utf-8')
            }
        ))

    except HomeAssistantError:
        connection.send_message(websocket_api.error_message(
            msg['id'], 'image_fetch_failed', 'Unable to fetch image')) 
开发者ID:pschmitt,项目名称:hass-config,代码行数:18,代码来源:camera.py

示例4: _async_entity_changed

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import entity_id [as 别名]
def _async_entity_changed(self, entity_id, old_state, new_state):
        """Handle entity change."""
        if new_state is None:
            return
        if new_state.state in (STATE_UNKNOWN, STATE_UNAVAILABLE):
            return

        if self.expose_attribute is not None:
            new_attribute = new_state.attributes.get(self.expose_attribute)
            if old_state is not None:
                old_attribute = old_state.attributes.get(self.expose_attribute)
                if old_attribute == new_attribute:
                    # don't send same value sequentially
                    return
            await self._async_set_knx_value(new_attribute)
        else:
            await self._async_set_knx_value(new_state.state) 
开发者ID:XKNX,项目名称:xknx,代码行数:19,代码来源:__init__.py

示例5: save_tasks

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import entity_id [as 别名]
def save_tasks(self):
        """save task config to disk"""
        tasks = [
            {
                'entity_id': attrs['entity_id'],
                'duration': attrs['duration'],
                'operation': attrs['operation'],
                'count': attrs['count'],
                'ratio': attrs['ratio']
            } 
            for entities in self._tasks.values() for entity_id, attrs in entities.items() if attrs['duration'] != '0:00:00' or attrs['count'] != 0
        ]
        # _LOGGER.debug('[stop()] save task config: <tasks=%s>',tasks)
        if not tasks:
            return
        data = {
            'tasks':tasks
        }
        yield from self._store.async_save(data) 
开发者ID:cnk700i,项目名称:common_timer,代码行数:21,代码来源:__init__.py

示例6: set_state

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import entity_id [as 别名]
def set_state(self, entity_id, state = None, attributes = None, service = None, force_update = False, context = None):
        """ set entity state. """
        if context is None:
            context = CONTEXT
        if service is None:
            _LOGGER.debug("[set_state] state machine: entity_id= {}, from {} to {}, context = {}".format(entity_id, self.get_state(entity_id), state, context))
            attr = self.get_attributes(entity_id)
            if attributes is not None:
                attr.update(attributes)
            self._hass.states.async_set(entity_id, state, attr, force_update = force_update, context = context)
        else:
            domain = entity_id.split('.')[0]
            _LOGGER.debug('[set_state] call service: entity_id =%s, context = %s',entity_id, context)
            # unused, after 0.78.0 fixed.
            # attr = self.get_attributes(entity_id)
            # if attributes is not None:
            #     attr.update(attributes)
            # change state directly with a context identification since call service can't pass context in code.
            # self._hass.states.async_set(entity_id, state, attr, force_update = force_update, context = CONTEXT)
            data = {'entity_id': entity_id}
            if state is not None:
                data.update(state)
            # call service to controll device
            # self._hass.services.async_call(domain, service, data, blocking = True, context = context )
            self._hass.async_add_job(self._hass.services.async_call(domain, service, data, context = context )) 
开发者ID:cnk700i,项目名称:common_timer,代码行数:27,代码来源:__init__.py

示例7: set_task

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import entity_id [as 别名]
def set_task(self, entity_id, operation, duration, is_loop):
        """ create new task, will overwrite previous task. """
        _LOGGER.debug('----set_task()-----')
        task = self._get_task(entity_id)
        if task is not None:
            self._queue.remove(task['handle'])
            task['duration'] = duration
            task['next_operation'] = operation
            if is_loop and 'custom:' not in operation:
                operation = 'temporary_' + operation
                state = 'off' if task['next_operation'] == 'on' else 'on'
                self.set_state(entity_id, service = 'turn_'+state, force_update = True)
            task['operation'] = operation
            task['handle'] = self._queue.insert(entity_id, duration, self.handle_task, operation = operation)  # initialize queue task
            task['exec_time'] = datetime.now() + self._queue.get_remaining_time(task['handle'])
            self._hass.async_add_job(self.update_info)  # refresh info panel
            if self._entity_id == entity_id:
                _LOGGER.debug("---set_task---")
                self.set_state(self._ui[UI_INPUT_OPERATION], state = self.get_operation(task = task))  # reset control panel ui
                self.set_state(self._ui[UI_INPUT_DURATION], state = task['duration'])
                self.set_state(self._ui[UI_SWITCH], state = 'on')
        else:
            _LOGGER.info('set up task for %s failure', entity_id) 
开发者ID:cnk700i,项目名称:common_timer,代码行数:25,代码来源:__init__.py

示例8: websocket_video_url

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import entity_id [as 别名]
def websocket_video_url(hass, connection, msg):
    try:
        camera = get_entity_from_domain(hass, DOMAIN, msg['entity_id'])
        video = camera.last_video
        url = video.video_url if video is not None else None
        url_type = video.content_type if video is not None else None
        thumbnail = video.thumbnail_url if video is not None else None
        connection.send_message(websocket_api.result_message(
            msg['id'], {
                'url': url,
                'url_type': url_type,
                'thumbnail': thumbnail,
                'thumbnail_type': 'image/jpeg',
            }
        ))
    except HomeAssistantError as error:
        connection.send_message(websocket_api.error_message(
            msg['id'], 'video_url_ws', "Unable to fetch url ({})".format(str(error))))
        _LOGGER.warning("{} video url websocket failed".format(msg['entity_id'])) 
开发者ID:twrecked,项目名称:hass-aarlo,代码行数:21,代码来源:camera.py

示例9: websocket_snapshot_image

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import entity_id [as 别名]
def websocket_snapshot_image(hass, connection, msg):
    try:
        camera = get_entity_from_domain(hass, DOMAIN, msg['entity_id'])
        _LOGGER.debug('snapshot_image for ' + str(camera.unique_id))

        image = await camera.async_get_snapshot()
        connection.send_message(websocket_api.result_message(
            msg['id'], {
                'content_type': camera.content_type,
                'content': base64.b64encode(image).decode('utf-8')
            }
        ))
    except HomeAssistantError as error:
        connection.send_message(websocket_api.error_message(
            msg['id'], 'snapshot_image_ws', "Unable to take snapshot ({})".format(str(error))))
        _LOGGER.warning("{} snapshot image websocket failed".format(msg['entity_id'])) 
开发者ID:twrecked,项目名称:hass-aarlo,代码行数:18,代码来源:camera.py

示例10: _async_temp_sensor_changed

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import entity_id [as 别名]
def _async_temp_sensor_changed(self, entity_id, old_state, new_state):
        _LOGGER.info('temp_sensor state changed |' + str(entity_id) + '|' + str(old_state) + '|' + str(new_state))
        # Handle temperature changes.
        if new_state is None:
            return
        self._async_update_current_temp(new_state)
        yield from self.async_update_ha_state() 
开发者ID:RobHofmann,项目名称:HomeAssistant-GreeClimateComponent,代码行数:9,代码来源:climate.py

示例11: _async_lights_entity_state_changed

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import entity_id [as 别名]
def _async_lights_entity_state_changed(self, entity_id, old_state, new_state):
        _LOGGER.info('lights_entity state changed |' + str(entity_id) + '|' + str(old_state) + '|' + str(new_state))
        if new_state is None:
            return
        if new_state.state is self._current_lights:
            # do nothing if state change is triggered due to Sync with HVAC
            return
        self._async_update_current_lights(new_state)
        yield from self.async_update_ha_state() 
开发者ID:RobHofmann,项目名称:HomeAssistant-GreeClimateComponent,代码行数:11,代码来源:climate.py

示例12: _async_xfan_entity_state_changed

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import entity_id [as 别名]
def _async_xfan_entity_state_changed(self, entity_id, old_state, new_state):
        _LOGGER.info('xfan_entity state changed |' + str(entity_id) + '|' + str(old_state) + '|' + str(new_state))
        if new_state is None:
            return
        if new_state.state is self._current_xfan:
            # do nothing if state change is triggered due to Sync with HVAC
            return
        if not self._hvac_mode in (HVAC_MODE_COOL, HVAC_MODE_DRY):
            # do nothing if not in cool or dry mode
            _LOGGER.info('Cant set xfan in %s mode' % str(self._hvac_mode))
            return
        self._async_update_current_xfan(new_state)
        yield from self.async_update_ha_state() 
开发者ID:RobHofmann,项目名称:HomeAssistant-GreeClimateComponent,代码行数:15,代码来源:climate.py

示例13: _async_health_entity_state_changed

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import entity_id [as 别名]
def _async_health_entity_state_changed(self, entity_id, old_state, new_state):
        _LOGGER.info('health_entity state changed |' + str(entity_id) + '|' + str(old_state) + '|' + str(new_state))
        if new_state is None:
            return
        if new_state.state is self._current_health:
            # do nothing if state change is triggered due to Sync with HVAC
            return
        self._async_update_current_health(new_state)
        yield from self.async_update_ha_state() 
开发者ID:RobHofmann,项目名称:HomeAssistant-GreeClimateComponent,代码行数:11,代码来源:climate.py

示例14: _async_powersave_entity_state_changed

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import entity_id [as 别名]
def _async_powersave_entity_state_changed(self, entity_id, old_state, new_state):
        _LOGGER.info('powersave_entity state changed |' + str(entity_id) + '|' + str(old_state) + '|' + str(new_state))
        if new_state is None:
            return
        if new_state.state is self._current_powersave:
            # do nothing if state change is triggered due to Sync with HVAC
            return
        if not self._hvac_mode in (HVAC_MODE_COOL):
            # do nothing if not in cool mode
            _LOGGER.info('Cant set powersave in %s mode' % str(self._hvac_mode))
            return
        self._async_update_current_powersave(new_state)
        yield from self.async_update_ha_state() 
开发者ID:RobHofmann,项目名称:HomeAssistant-GreeClimateComponent,代码行数:15,代码来源:climate.py

示例15: _async_eightdegheat_entity_state_changed

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import entity_id [as 别名]
def _async_eightdegheat_entity_state_changed(self, entity_id, old_state, new_state):
        _LOGGER.info('eightdegheat_entity state changed |' + str(entity_id) + '|' + str(old_state) + '|' + str(new_state))
        if new_state is None:
            return
        if new_state.state is self._current_eightdegheat:
            # do nothing if state change is triggered due to Sync with HVAC
            return
        if not self._hvac_mode in (HVAC_MODE_HEAT):
            # do nothing if not in heat mode
            _LOGGER.info('Cant set 8℃ heat in %s mode' % str(self._hvac_mode))
            return
        self._async_update_current_eightdegheat(new_state)
        yield from self.async_update_ha_state() 
开发者ID:RobHofmann,项目名称:HomeAssistant-GreeClimateComponent,代码行数:15,代码来源:climate.py


注:本文中的homeassistant.helpers.config_validation.entity_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。