示例#1
0
    def async_owntracks_waypoint_update(topic, payload, qos):
        """List of waypoints published by a user."""
        # Docs on available data:
        # http://owntracks.org/booklet/tech/json/#_typewaypoints
        data = validate_payload(topic, payload, VALIDATE_WAYPOINTS)
        if not data:
            return

        wayps = data['waypoints']
        _LOGGER.info("Got %d waypoints from %s", len(wayps), topic)
        for wayp in wayps:
            name = wayp['desc']
            pretty_name = parse_topic(topic, True)[1] + ' - ' + name
            lat = wayp[WAYPOINT_LAT_KEY]
            lon = wayp[WAYPOINT_LON_KEY]
            rad = wayp['rad']

            # check zone exists
            entity_id = zone_comp.ENTITY_ID_FORMAT.format(slugify(pretty_name))

            # Check if state already exists
            if hass.states.get(entity_id) is not None:
                continue

            zone = zone_comp.Zone(hass, pretty_name, lat, lon, rad,
                                  zone_comp.ICON_IMPORT, False)
            zone.entity_id = entity_id
            hass.async_add_job(zone.async_update_ha_state())
示例#2
0
async def async_handle_waypoint(hass, name_base, waypoint):
    """Handle a waypoint."""
    name = waypoint["desc"]
    pretty_name = f"{name_base} - {name}"
    lat = waypoint["lat"]
    lon = waypoint["lon"]
    rad = waypoint["rad"]

    # check zone exists
    entity_id = zone_comp.ENTITY_ID_FORMAT.format(slugify(pretty_name))

    # Check if state already exists
    if hass.states.get(entity_id) is not None:
        return

    zone = zone_comp.Zone(
        {
            zone_comp.CONF_NAME: pretty_name,
            zone_comp.CONF_LATITUDE: lat,
            zone_comp.CONF_LONGITUDE: lon,
            zone_comp.CONF_RADIUS: rad,
            zone_comp.CONF_ICON: zone_comp.ICON_IMPORT,
            zone_comp.CONF_PASSIVE: False,
        },
        False,
    )
    zone.hass = hass
    zone.entity_id = entity_id
    zone.async_write_ha_state()
def async_handle_waypoints_message(hass, context, message):
    """Handle a waypoints message."""
    if not context.import_waypoints:
        return

    if context.waypoint_whitelist is not None:
        user = _parse_topic(message['topic'])[0]

        if user not in context.waypoint_whitelist:
            return

    wayps = message['waypoints']

    _LOGGER.info("Got %d waypoints from %s", len(wayps), message['topic'])

    name_base = ' '.join(_parse_topic(message['topic']))

    for wayp in wayps:
        name = wayp['desc']
        pretty_name = '{} - {}'.format(name_base, name)
        lat = wayp['lat']
        lon = wayp['lon']
        rad = wayp['rad']

        # check zone exists
        entity_id = zone_comp.ENTITY_ID_FORMAT.format(slugify(pretty_name))

        # Check if state already exists
        if hass.states.get(entity_id) is not None:
            continue

        zone = zone_comp.Zone(hass, pretty_name, lat, lon, rad,
                              zone_comp.ICON_IMPORT, False)
        zone.entity_id = entity_id
        yield from zone.async_update_ha_state()
示例#4
0
async def async_handle_waypoint(hass, name_base, waypoint):
    """Handle a waypoint."""
    name = waypoint['desc']
    pretty_name = '{} - {}'.format(name_base, name)
    lat = waypoint['lat']
    lon = waypoint['lon']
    rad = waypoint['rad']

    # check zone exists
    entity_id = zone_comp.ENTITY_ID_FORMAT.format(slugify(pretty_name))

    # Check if state already exists
    if hass.states.get(entity_id) is not None:
        return

    zone = zone_comp.Zone(hass, pretty_name, lat, lon, rad,
                          zone_comp.ICON_IMPORT, False)
    zone.entity_id = entity_id
    await zone.async_update_ha_state()
示例#5
0
    def owntracks_waypoint_update(topic, payload, qos):
        """List of waypoints published by a user."""
        # Docs on available data:
        # http://owntracks.org/booklet/tech/json/#_typewaypoints
        data = validate_payload(payload, VALIDATE_WAYPOINTS)
        if not data:
            return

        wayps = data['waypoints']
        _LOGGER.info("Got %d waypoints from %s", len(wayps), topic)
        for wayp in wayps:
            name = wayp['desc']
            pretty_name = parse_topic(topic, True)[1] + ' - ' + name
            lat = wayp[WAYPOINT_LAT_KEY]
            lon = wayp[WAYPOINT_LON_KEY]
            rad = wayp['rad']
            zone = zone_comp.Zone(hass, pretty_name, lat, lon, rad,
                                  zone_comp.ICON_IMPORT, False, True)
            zone_comp.add_zone(hass, pretty_name, zone)