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