本文整理汇总了Python中homeassistant.helpers.discovery.async_load_platform方法的典型用法代码示例。如果您正苦于以下问题:Python discovery.async_load_platform方法的具体用法?Python discovery.async_load_platform怎么用?Python discovery.async_load_platform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类homeassistant.helpers.discovery
的用法示例。
在下文中一共展示了discovery.async_load_platform方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: async_setup
# 需要导入模块: from homeassistant.helpers import discovery [as 别名]
# 或者: from homeassistant.helpers.discovery import async_load_platform [as 别名]
def async_setup(hass, config):
"""Setup the duofern platform."""
serial_port = config.get('serial_port')
code = config.get('code')
configfile = config.get('config_file')
hass.data['duofern'] = {
'stick': DuofernStickAsync(serial_port=serial_port, system_code=code, config_file_json=configfile)}
hass.loop.create_task(hass.data['duofern']['stick'].handshake())
# wait for handshake done (via future)
await hass.data['duofern']['stick'].available
# wait for a bit to allow duofern devices to call in
await asyncio.sleep(10)
hass.async_add_job(discovery.async_load_platform(hass, 'cover', DOMAIN, {}, config))
# hass.async_add_job(discovery.async_load_platform(hass, 'sensor', DOMAIN, {}, config))
示例2: add_sensor
# 需要导入模块: from homeassistant.helpers import discovery [as 别名]
# 或者: from homeassistant.helpers.discovery import async_load_platform [as 别名]
def add_sensor():
"""Add sensor."""
hacs = get_hacs()
try:
if hacs.configuration.config_type == "yaml":
hacs.hass.async_create_task(
discovery.async_load_platform(
hacs.hass, "sensor", DOMAIN, {}, hacs.configuration.config
)
)
else:
hacs.hass.async_add_job(
hacs.hass.config_entries.async_forward_entry_setup(
hacs.configuration.config_entry, "sensor"
)
)
except ValueError:
pass
示例3: async_setup
# 需要导入模块: from homeassistant.helpers import discovery [as 别名]
# 或者: from homeassistant.helpers.discovery import async_load_platform [as 别名]
def async_setup(hass, config):
"""Set up the KNX component."""
try:
hass.data[DATA_XKNX] = KNXModule(hass, config)
hass.data[DATA_XKNX].async_create_exposures()
await hass.data[DATA_XKNX].start()
except XKNXException as ex:
_LOGGER.warning("Can't connect to KNX interface: %s", ex)
hass.components.persistent_notification.async_create(
f"Can't connect to KNX interface: <br><b>{ex}</b>", title="KNX"
)
for component, discovery_type in (
("switch", "Switch"),
("climate", "Climate"),
("cover", "Cover"),
("light", "Light"),
("sensor", "Sensor"),
("binary_sensor", "BinarySensor"),
("scene", "Scene"),
("notify", "Notification"),
):
found_devices = _get_devices(hass, discovery_type)
hass.async_create_task(
discovery.async_load_platform(
hass, component, DOMAIN, {ATTR_DISCOVER_DEVICES: found_devices}, config
)
)
hass.services.async_register(
DOMAIN,
SERVICE_XKNX_SEND,
hass.data[DATA_XKNX].service_send_to_knx_bus,
schema=SERVICE_XKNX_SEND_SCHEMA,
)
return True
示例4: async_setup
# 需要导入模块: from homeassistant.helpers import discovery [as 别名]
# 或者: from homeassistant.helpers.discovery import async_load_platform [as 别名]
def async_setup(hass, config):
"""Set up this component using YAML."""
if config.get(DOMAIN) is None:
# config flow setup
return True
# log startup message
_LOGGER.info(
CC_STARTUP_VERSION.format(name=DOMAIN, version=VERSION, issue_link=ISSUE_URL)
)
platform_config = config[DOMAIN].get(CONF_SENSORS, {})
# If platform is not enabled, skip.
if not platform_config:
return False
for entry in platform_config:
hass.async_create_task(
discovery.async_load_platform(hass, PLATFORM, DOMAIN, entry, config)
)
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={}
)
)
return True
示例5: async_setup
# 需要导入模块: from homeassistant.helpers import discovery [as 别名]
# 或者: from homeassistant.helpers.discovery import async_load_platform [as 别名]
def async_setup(hass, config):
"""Set up the WyzeApi parent component."""
_LOGGER.debug("""
-------------------------------------------------------------------
Wyze Bulb and Switch Home Assistant Integration
Version: v0.5.0
This is a custom integration
If you have any issues with this you need to open an issue here:
https://github.com/JoshuaMulliken/ha-wyzeapi/issues
-------------------------------------------------------------------""")
_LOGGER.debug("""Creating new WyzeApi component""")
wyzeapi_account = WyzeApi(config[DOMAIN].get(CONF_USERNAME),
config[DOMAIN].get(CONF_PASSWORD))
await wyzeapi_account.async_init()
sensor_support = config[DOMAIN].get(CONF_SENSORS)
light_support = config[DOMAIN].get(CONF_LIGHT)
switch_support = config[DOMAIN].get(CONF_SWITCH)
lock_support = config[DOMAIN].get(CONF_LOCK)
if not wyzeapi_account.is_valid_login():
_LOGGER.error("Not connected to Wyze account. Unable to add devices. Check your configuration.")
return False
_LOGGER.debug("Connected to Wyze account")
wyzeapi_devices = await wyzeapi_account.async_get_devices()
# Store the logged in account object for the platforms to use.
hass.data[DOMAIN] = {
"wyzeapi_account": wyzeapi_account
}
# Start up lights and switch components
if wyzeapi_devices:
_LOGGER.debug("Starting WyzeApi components")
if light_support == True:
await discovery.async_load_platform(hass, "light", DOMAIN, {}, config)
_LOGGER.debug("Starting WyzeApi Lights")
if switch_support == True:
await discovery.async_load_platform(hass, "switch", DOMAIN, {}, config)
_LOGGER.debug("Starting WyzeApi switchs")
if sensor_support == True:
await discovery.async_load_platform(hass, "binary_sensor", DOMAIN, {}, config)
_LOGGER.debug("Starting WyzeApi Sensors")
if lock_support == True:
await discovery.async_load_platform(hass, "lock", DOMAIN, {}, config)
_LOGGER.debug("Starting WyzeApi lock")
else:
_LOGGER.error("WyzeApi authenticated but could not find any devices.")
return True
示例6: async_setup
# 需要导入模块: from homeassistant.helpers import discovery [as 别名]
# 或者: from homeassistant.helpers.discovery import async_load_platform [as 别名]
def async_setup(hass, config):
"""Set up this component."""
# Print startup message
startup = STARTUP.format(name=DOMAIN, version=VERSION, issueurl=ISSUE_URL)
_LOGGER.info(startup)
throttle = Throttle()
# Check that all required files are present
file_check = await check_files(hass)
if not file_check:
return False
# Create DATA dict
hass.data[DOMAIN_DATA] = {}
hass.data[DOMAIN_DATA]["throttle"] = throttle
hass.data[DOMAIN_DATA]["components"] = ["homeassistant"]
hass.data[DOMAIN_DATA]["potential"] = {}
if config[DOMAIN].get("scan_interval") is not None:
throttle.interval = timedelta(seconds=config[DOMAIN].get("scan_interval"))
# Load platforms
for platform in PLATFORMS:
# Get platform specific configuration
platform_config = config[DOMAIN]
hass.async_create_task(
discovery.async_load_platform(
hass, platform, DOMAIN, platform_config, config
)
)
async def loaded_platforms(hass):
"""Load platforms after HA startup."""
for component in hass.config.components:
hass.data[DOMAIN_DATA]["components"].append(component)
_LOGGER.debug("Loaded components %s", hass.data[DOMAIN_DATA]["components"])
await update_data(hass, throttle) # pylint: disable=unexpected-keyword-arg
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, loaded_platforms(hass))
return True
示例7: setup
# 需要导入模块: from homeassistant.helpers import discovery [as 别名]
# 或者: from homeassistant.helpers.discovery import async_load_platform [as 别名]
def setup(hass, config):
"""Set up MercedesMe System."""
conf = config[DOMAIN]
scan_interval = conf.get(CONF_SCAN_INTERVAL)
cache = hass.config.path(DEFAULT_CACHE_PATH)
auth_handler = MercedesMeOAuth(
conf.get(CONF_USERNAME),
conf.get(CONF_PASSWORD),
conf.get(CONF_ACCEPT_LANG),
conf.get(CONF_COUNTRY_CODE),
cache,
)
token_info = auth_handler.get_cached_token()
if not token_info:
_LOGGER.debug("no token; requesting authorization")
token_info = auth_handler.request_initial_token()
else:
_LOGGER.debug("cached token found")
if not token_info:
_LOGGER.warning("no token; authorization failed; check debug log")
return False
mercedesme_api = Controller(
auth_handler,
scan_interval,
conf.get(CONF_ACCEPT_LANG),
conf.get(CONF_COUNTRY_CODE),
conf.get(CONF_EXCLUDED_CARS),
conf.get(CONF_SAVE_CAR_DETAILS),
conf.get(CONF_PIN),
hass.config.path(""),
)
hass.data[DOMAIN] = MercedesMeHub(mercedesme_api, conf)
for component in MERCEDESME_COMPONENTS:
hass.async_create_task(
discovery.async_load_platform(hass, component, DOMAIN, {}, config)
)
def hub_refresh(event_time):
"""Call Mercedes me API to refresh information."""
_LOGGER.info("Updating Mercedes me component.")
hass.data[DOMAIN].data.update()
dispatcher_send(hass, SIGNAL_UPDATE_MERCEDESME)
track_time_interval(hass, hub_refresh, timedelta(seconds=scan_interval))
return True
示例8: async_setup_bridge
# 需要导入模块: from homeassistant.helpers import discovery [as 别名]
# 或者: from homeassistant.helpers.discovery import async_load_platform [as 别名]
def async_setup_bridge(hass, config, fname, bridge):
"""Initialize a bridge by loading its integration report."""
_LOGGER.debug("Setting up bridge using Integration Report %s", fname)
devices = await casetify.async_load_integration_report(fname)
# Patch up device types from configuration.
# All other devices will be treated as lights.
await _patch_device_types(bridge, devices)
_LOGGER.debug("Patched device list %s", devices)
# sort devices based on device types
types = {
"sensor": [],
"switch": [],
"light": [],
"cover": [],
"scene": [],
"fan": [],
}
for device in devices:
types[device["type"]].append(device)
# load MAC address used for unique IDs
mac_address = None
if CONF_MAC in bridge:
mac_address = bridge[CONF_MAC]
# Load default transition time, if present.
transition_time = None
if CONF_TRANSITION_TIME in bridge:
transition_time = bridge[CONF_TRANSITION_TIME]
# load platform by type
for device_type in types:
component = device_type
_LOGGER.debug("Loading platform %s", component)
hass.async_add_job(
discovery.async_load_platform(
hass,
component,
DOMAIN,
{
CONF_HOST: bridge[CONF_HOST],
CONF_MAC: mac_address,
CONF_DEVICES: types[device_type],
CONF_TRANSITION_TIME: transition_time,
},
config,
)
)