當前位置: 首頁>>代碼示例>>Python>>正文


Python entity.Entity類代碼示例

本文整理匯總了Python中homeassistant.helpers.entity.Entity的典型用法代碼示例。如果您正苦於以下問題:Python Entity類的具體用法?Python Entity怎麽用?Python Entity使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Entity類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: setup

def setup(hass, config):
    """ Setup myhome component. """

    home = MyHome(hass)
    room_conf = config[DOMAIN].get(CONF_ROOMS, {})
    for name, conf in room_conf.items():
        room = create_room(hass, name, conf)
        room.update_ha_state()
        home.add(room)
        # hide all the scenes related to this room
        for name in hass.states.entity_ids(DOMAIN_SCENE):
            if name.startswith('{}.{}'.format(DOMAIN_SCENE, room.name.lower())):
                Entity.overwrite_attribute(name, [ATTR_HIDDEN], [True])
                state = hass.states.get(name)
                hass.states.set(name, state, {ATTR_HIDDEN: True})

    register_room_services(hass, home)

    home.update_ha_state()
    _LOGGER.info('myhome loaded: %s', home)

    register_presence_handlers(hass, config)
    _LOGGER.info('registered presense handlers')

    return True
開發者ID:darookee,項目名稱:hass-config,代碼行數:25,代碼來源:myhome.py

示例2: _compute_state

    def _compute_state(self, config):
        run_coroutine_threadsafe(
            config_util.async_process_ha_core_config(self.hass, config),
            self.hass.loop).result()

        entity = Entity()
        entity.entity_id = 'test.test'
        entity.hass = self.hass
        entity.schedule_update_ha_state()

        self.hass.block_till_done()

        return self.hass.states.get('test.test')
開發者ID:chilicheech,項目名稱:home-assistant,代碼行數:13,代碼來源:test_config.py

示例3: test_entity_customization

    def test_entity_customization(self):
        """Test entity customization through configuration."""
        config = {CONF_LATITUDE: 50,
                  CONF_LONGITUDE: 50,
                  CONF_NAME: 'Test',
                  CONF_CUSTOMIZE: {'test.test': {'hidden': True}}}

        bootstrap.process_ha_core_config(self.hass, config)

        entity = Entity()
        entity.entity_id = 'test.test'
        entity.hass = self.hass
        entity.update_ha_state()

        state = self.hass.states.get('test.test')

        assert state.attributes['hidden']
開發者ID:1lann,項目名稱:home-assistant,代碼行數:17,代碼來源:test_bootstrap.py

示例4: test_entity_customization

    def test_entity_customization(self):
        """ Test entity customization through config """
        config = {CONF_LATITUDE: 50,
                  CONF_LONGITUDE: 50,
                  CONF_NAME: 'Test',
                  CONF_CUSTOMIZE: {'test.test': {'hidden': True}}}

        hass = get_test_home_assistant()

        bootstrap.process_ha_core_config(hass, config)

        entity = Entity()
        entity.entity_id = 'test.test'
        entity.hass = hass
        entity.update_ha_state()

        state = hass.states.get('test.test')

        self.assertTrue(state.attributes['hidden'])
        hass.stop()
開發者ID:100dayproject,項目名稱:home-assistant,代碼行數:20,代碼來源:test_bootstrap.py

示例5: test_entity_customization

    def test_entity_customization(self):
        """Test entity customization through configuration."""
        self.hass = get_test_home_assistant()

        config = {CONF_LATITUDE: 50,
                  CONF_LONGITUDE: 50,
                  CONF_NAME: 'Test',
                  CONF_CUSTOMIZE: {'test.test': {'hidden': True}}}

        config_util.process_ha_core_config(self.hass, config)

        entity = Entity()
        entity.entity_id = 'test.test'
        entity.hass = self.hass
        entity.update_ha_state()

        self.hass.block_till_done()

        state = self.hass.states.get('test.test')

        assert state.attributes['hidden']
開發者ID:krzynio,項目名稱:home-assistant,代碼行數:21,代碼來源:test_config.py

示例6: test_entity_customization

    def test_entity_customization(self):
        """Test entity customization through configuration."""
        config = {CONF_LATITUDE: 50,
                  CONF_LONGITUDE: 50,
                  CONF_NAME: 'Test',
                  CONF_CUSTOMIZE: {'test.test': {'hidden': True}}}

        run_coroutine_threadsafe(
            config_util.async_process_ha_core_config(self.hass, config),
            self.hass.loop).result()

        entity = Entity()
        entity.entity_id = 'test.test'
        entity.hass = self.hass
        entity.update_ha_state()

        self.hass.block_till_done()

        state = self.hass.states.get('test.test')

        assert state.attributes['hidden']
開發者ID:DavidLP,項目名稱:home-assistant,代碼行數:21,代碼來源:test_config.py

示例7: process_ha_core_config

def process_ha_core_config(hass, config):
    """ Processes the [homeassistant] section from the config. """
    for key, attr in ((CONF_LATITUDE, 'latitude'),
                      (CONF_LONGITUDE, 'longitude'),
                      (CONF_NAME, 'location_name'),
                      (CONF_TIME_ZONE, 'time_zone')):
        if key in config:
            setattr(hass.config, attr, config[key])

    for entity_id, hidden in config.get(CONF_VISIBILITY, {}).items():
        Entity.overwrite_hidden(entity_id, hidden == 'hide')

    if CONF_TEMPERATURE_UNIT in config:
        unit = config[CONF_TEMPERATURE_UNIT]

        if unit == 'C':
            hass.config.temperature_unit = TEMP_CELCIUS
        elif unit == 'F':
            hass.config.temperature_unit = TEMP_FAHRENHEIT

    hass.config.auto_detect()
開發者ID:Bakeneko,項目名稱:home-assistant,代碼行數:21,代碼來源:bootstrap.py

示例8: test_merge_customize

def test_merge_customize(hass):
    """Test loading core config onto hass object."""
    core_config = {
        'latitude': 60,
        'longitude': 50,
        'elevation': 25,
        'name': 'Huis',
        CONF_UNIT_SYSTEM: CONF_UNIT_SYSTEM_IMPERIAL,
        'time_zone': 'GMT',
        'customize': {'a.a': {'friendly_name': 'A'}},
        'packages': {'pkg1': {'homeassistant': {'customize': {
            'b.b': {'friendly_name': 'BB'}}}}},
    }
    yield from config_util.async_process_ha_core_config(hass, core_config)

    entity = Entity()
    entity.entity_id = 'b.b'
    entity.hass = hass
    yield from entity.async_update_ha_state()

    state = hass.states.get('b.b')
    assert state is not None
    assert state.attributes['friendly_name'] == 'BB'
開發者ID:Teagan42,項目名稱:home-assistant,代碼行數:23,代碼來源:test_config.py

示例9: process_ha_core_config

def process_ha_core_config(hass, config):
    """ Processes the [homeassistant] section from the config. """
    hac = hass.config

    def set_time_zone(time_zone_str):
        """ Helper method to set time zone in HA. """
        if time_zone_str is None:
            return

        time_zone = date_util.get_time_zone(time_zone_str)

        if time_zone:
            hac.time_zone = time_zone
            date_util.set_default_time_zone(time_zone)
        else:
            _LOGGER.error("Received invalid time zone %s", time_zone_str)

    for key, attr in ((CONF_LATITUDE, "latitude"), (CONF_LONGITUDE, "longitude"), (CONF_NAME, "location_name")):
        if key in config:
            setattr(hac, attr, config[key])

    set_time_zone(config.get(CONF_TIME_ZONE))

    for entity_id, attrs in config.get(CONF_CUSTOMIZE, {}).items():
        Entity.overwrite_attribute(entity_id, attrs.keys(), attrs.values())

    if CONF_TEMPERATURE_UNIT in config:
        unit = config[CONF_TEMPERATURE_UNIT]

        if unit == "C":
            hac.temperature_unit = TEMP_CELCIUS
        elif unit == "F":
            hac.temperature_unit = TEMP_FAHRENHEIT

    # If we miss some of the needed values, auto detect them
    if None not in (hac.latitude, hac.longitude, hac.temperature_unit, hac.time_zone):
        return

    _LOGGER.info("Auto detecting location and temperature unit")

    info = util.detect_location_info()

    if info is None:
        _LOGGER.error("Could not detect location information")
        return

    if hac.latitude is None and hac.longitude is None:
        hac.latitude = info.latitude
        hac.longitude = info.longitude

    if hac.temperature_unit is None:
        if info.use_fahrenheit:
            hac.temperature_unit = TEMP_FAHRENHEIT
        else:
            hac.temperature_unit = TEMP_CELCIUS

    if hac.location_name is None:
        hac.location_name = info.city

    if hac.time_zone is None:
        set_time_zone(info.time_zone)
開發者ID:nodejsfy,項目名稱:home-assistant,代碼行數:61,代碼來源:bootstrap.py

示例10: process_ha_core_config

def process_ha_core_config(hass, config):
    """ Processes the [homeassistant] section from the config. """
    hac = hass.config

    def set_time_zone(time_zone_str):
        """ Helper method to set time zone in HA. """
        if time_zone_str is None:
            return

        time_zone = date_util.get_time_zone(time_zone_str)

        if time_zone:
            hac.time_zone = time_zone
            date_util.set_default_time_zone(time_zone)
        else:
            _LOGGER.error('Received invalid time zone %s', time_zone_str)

    for key, attr, typ in ((CONF_LATITUDE, 'latitude', float),
                           (CONF_LONGITUDE, 'longitude', float),
                           (CONF_NAME, 'location_name', str)):
        if key in config:
            try:
                setattr(hac, attr, typ(config[key]))
            except ValueError:
                _LOGGER.error('Received invalid %s value for %s: %s',
                              typ.__name__, key, attr)

    set_time_zone(config.get(CONF_TIME_ZONE))

    customize = config.get(CONF_CUSTOMIZE)

    if isinstance(customize, dict):
        for entity_id, attrs in config.get(CONF_CUSTOMIZE, {}).items():
            if not isinstance(attrs, dict):
                continue
            Entity.overwrite_attribute(entity_id, attrs.keys(), attrs.values())

    if CONF_TEMPERATURE_UNIT in config:
        unit = config[CONF_TEMPERATURE_UNIT]

        if unit == 'C':
            hac.temperature_unit = TEMP_CELCIUS
        elif unit == 'F':
            hac.temperature_unit = TEMP_FAHRENHEIT

    # If we miss some of the needed values, auto detect them
    if None not in (
            hac.latitude, hac.longitude, hac.temperature_unit, hac.time_zone):
        return

    _LOGGER.info('Auto detecting location and temperature unit')

    info = loc_util.detect_location_info()

    if info is None:
        _LOGGER.error('Could not detect location information')
        return

    if hac.latitude is None and hac.longitude is None:
        hac.latitude = info.latitude
        hac.longitude = info.longitude

    if hac.temperature_unit is None:
        if info.use_fahrenheit:
            hac.temperature_unit = TEMP_FAHRENHEIT
        else:
            hac.temperature_unit = TEMP_CELCIUS

    if hac.location_name is None:
        hac.location_name = info.city

    if hac.time_zone is None:
        set_time_zone(info.time_zone)
開發者ID:Jocke1970,項目名稱:home-assistant,代碼行數:73,代碼來源:bootstrap.py


注:本文中的homeassistant.helpers.entity.Entity類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。