예제 #1
0
def _status_update(device):
    status = "online" if int(device["status"]) else "offline"
    LOGGER.debug("Updating device %s", device["mac"])
    eventbuilder.eEvent(
        sender_id=PLUGIN.name,
        keyword="network.fritzbox.availability.{}.{}".format(
            status, device["name"]),
        data=device).trigger()
    context.set_property("network.devices.{}".format(device["mac"]), device)
예제 #2
0
    def _check_daytime(datetime_obj, timelist):
        if (SUNSET < SUNRISE < datetime_obj or
                SUNRISE < datetime_obj < SUNSET or
                datetime_obj < SUNSET < SUNRISE):
            # The sun has risen.
            time_of_day = "day"
        else:
            # The sun hasn't risen yet.
            time_of_day = "night"

        if time_of_day == context.get_value("time.time_of_day", None):
            logger.debug("It's still %stime.", time_of_day)
        else:
            logger.debug("It's now %stime.", time_of_day)
            context.set_property("time.time_of_day", time_of_day)
            keyword = "time.time_of_day.{}".format(time_of_day)
            eventbuilder.eEvent(sender_id=name,
                                keyword=keyword,
                                data=timelist).trigger()

        # calculate time between now and sunrise
        if SUNRISE < datetime_obj:
            # the sunrise is in the past
            sunrise_pre_post = "post"
            diff_sunrise = datetime_obj - SUNRISE
        else:
            # the sunrise is in the future
            sunrise_pre_post = "pre"
            diff_sunrise = SUNRISE - datetime_obj
        if 0 < diff_sunrise.seconds % 300 < 59:
            # the difference between now and the sunrise is a multiple of 5
            # minutes (this check is executed every minute, thus I'm checking
            # this in a way that the condition becomes true every 5th minute.
            keyword_sunrise = "time.sunrise.{}.{}".format(
                sunrise_pre_post,
                diff_sunrise.seconds / 60)
            LOGGER.warn("Triggering event '%s'!", keyword_sunrise)
            eventbuilder.eEvent(sender_id=name,
                                keyword=keyword_sunrise,
                                data=timelist).trigger()

        # calculate time between now and sunset
        if SUNSET < datetime_obj:
            # the sunset is in the past
            sunset_pre_post = "post"
            diff_sunset = datetime_obj - SUNSET
        else:
            # the sunset is in the future
            sunset_pre_post = "pre"
            diff_sunset = SUNSET - datetime_obj
        if 0 < diff_sunset.seconds % 300 < 59:
            # the difference between now and the sunset is a multiple of 5
            # minutes (this check is executed every minute, thus I'm checking
            # this in a way that the condition becomes true every 5th minute.
            keyword_sunset = "time.sunset.{}.{}".format(
                sunset_pre_post,
                diff_sunset.seconds / 60)
            LOGGER.warn("Triggering event '%s'!", keyword_sunset)
            eventbuilder.eEvent(sender_id=name,
                                keyword=keyword_sunset,
                                data=timelist).trigger()

        logger.debug("SUNRISE: %s, SUNSET: %s, NOW: %s",
                     SUNRISE, SUNSET, datetime_obj)
예제 #3
0
     .encode("utf-8").decode("utf-8")
 current_game = item["channel"]["game"] \
     .encode("utf-8").decode("utf-8")
 # save the stream's data in a new list
 new_streamlist[channelname] = item
 if (channelname not in STREAM_LIST or
         STREAM_LIST[channelname] is None):
     # The stream came online since the last check
     LOGGER.debug(u"'%s' is now online. Playing '%s'",
                  channelname, current_game)
     eventbuilder.eEvent(
         sender_id=PLUGIN.name,
         keyword="media.twitch.availability.online.{}".format(
             channelname),
         data=item).trigger()
     context.set_property(
         "media.twitch.{}".format(channelname), item)
     if channelname in STREAM_LIST:
         # remove the channel from STREAM_LIST so that it can be
         # refilled with the new data
         del STREAM_LIST[channelname]
 else:
     # The channel was already online at the last check
     if current_game == STREAM_LIST[channelname]["channel"]["game"]:
         # The game hasn't changed
         LOGGER.debug("'%s' is still playing '%s'.",
                      channelname, current_game)
     else:
         # The game changed
         LOGGER.debug("'%s' is now playing '%s'",
                      channelname, current_game)
         eventbuilder.eEvent(