本文整理汇总了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
示例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)
示例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)