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


Python Entity.overwrite_attribute方法代碼示例

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


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

示例1: setup

# 需要導入模塊: from homeassistant.helpers.entity import Entity [as 別名]
# 或者: from homeassistant.helpers.entity.Entity import overwrite_attribute [as 別名]
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,代碼行數:27,代碼來源:myhome.py

示例2: process_ha_core_config

# 需要導入模塊: from homeassistant.helpers.entity import Entity [as 別名]
# 或者: from homeassistant.helpers.entity.Entity import overwrite_attribute [as 別名]
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,代碼行數:63,代碼來源:bootstrap.py

示例3: process_ha_core_config

# 需要導入模塊: from homeassistant.helpers.entity import Entity [as 別名]
# 或者: from homeassistant.helpers.entity.Entity import overwrite_attribute [as 別名]
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,代碼行數:75,代碼來源:bootstrap.py


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