Example #1
0
async def async_setup_platform(opp,
                               config,
                               async_add_entities,
                               discovery_info=None):
    """Set up the Yr.no sensor."""
    elevation = config.get(CONF_ELEVATION, opp.config.elevation or 0)
    forecast = config.get(CONF_FORECAST)
    latitude = config.get(CONF_LATITUDE, opp.config.latitude)
    longitude = config.get(CONF_LONGITUDE, opp.config.longitude)
    name = config.get(CONF_NAME)

    if None in (latitude, longitude):
        _LOGGER.error(
            "Latitude or longitude not set in Open Peer Power config")
        return False

    coordinates = {
        "lat": str(latitude),
        "lon": str(longitude),
        "msl": str(elevation)
    }

    dev = []
    for sensor_type in config[CONF_MONITORED_CONDITIONS]:
        dev.append(YrSensor(name, sensor_type))
    async_add_entities(dev)

    weather = YrData(opp, coordinates, forecast, dev)
    async_track_utc_time_change(opp,
                                weather.updating_devices,
                                minute=31,
                                second=0)
    await weather.fetching_data()
async def async_setup(opp: OpenPeerPowerType, config: ConfigType):
    """Set up the device tracker."""
    tracker = await legacy.get_tracker(opp, config)

    legacy_platforms = await setup.async_extract_config(opp, config)

    setup_tasks = [
        legacy_platform.async_setup_legacy(opp, tracker)
        for legacy_platform in legacy_platforms
    ]

    if setup_tasks:
        await asyncio.wait(setup_tasks)

    async def async_platform_discovered(p_type, info):
        """Load a platform."""
        platform = await setup.async_create_platform_type(
            opp, config, p_type, {})

        if platform is None or platform.type != PLATFORM_TYPE_LEGACY:
            return

        await platform.async_setup_legacy(opp, tracker, info)

    discovery.async_listen_platform(opp, DOMAIN, async_platform_discovered)

    # Clean up stale devices
    async_track_utc_time_change(opp,
                                tracker.async_update_stale,
                                second=range(0, 60, 5))

    async def async_see_service(call):
        """Service to see a device."""
        # Temp workaround for iOS, introduced in 0.65
        data = dict(call.data)
        data.pop("hostname", None)
        data.pop("battery_status", None)
        await tracker.async_see(**data)

    opp.services.async_register(DOMAIN, SERVICE_SEE, async_see_service,
                                SERVICE_SEE_PAYLOAD_SCHEMA)

    # restore
    await tracker.async_setup_tracked_device()
    return True
Example #3
0
 def _listen_cover_tilt(self):
     """Listen for changes in cover tilt."""
     if self._unsub_listener_cover_tilt is None:
         self._unsub_listener_cover_tilt = async_track_utc_time_change(
             self.opp, self._time_changed_cover_tilt
         )