예제 #1
0
def onEmailAddressesChanged(event):
    email_addresses = scope.items[event.itemName].toString()
    if email_addresses is not None and email_addresses != '':
        attachmentState = scope.items['EmailAttachmentUrls']
        if scope.UnDefType.NULL ==  attachmentState \
                or scope.UnDefType.UNDEF == attachmentState \
                or attachmentState.toString() == '':
            attachment_urls = []
        else:
            attachment_urls = attachmentState.toString().split(', ')

        bodyState = scope.items['EmailBody']
        if scope.UnDefType.NULL == bodyState or scope.UnDefType.UNDEF == bodyState:
            body = ''
        else:
            body = bodyState.toString()

        logger.info(
            u"Sending email to '{}' for subject '{}', body '{}'".format(
                email_addresses, scope.items['EmailSubject'].toString(),
                scope.items['EmailBody']))

        actions.get("mail", "mail:smtp:gmail").sendMail(
            email_addresses, scope.items['EmailSubject'].toString(), body)

        # reset the item to wait for the next message.
        scope.events.sendCommand(event.itemName, '')
        scope.events.sendCommand("EmailSubject", '')
        scope.events.sendCommand("EmailBody", '')
        scope.events.sendCommand("EmailAttachmentUrls", '')
예제 #2
0
    def _emailAlert(alert, defaultEmailAddresses):
        emailAddresses = alert.getEmailAddresses()
        if [] == emailAddresses:
            emailAddresses = defaultEmailAddresses

        if None == emailAddresses or len(emailAddresses) == 0:
            raise ValueError('Missing email addresses.')

        if not AlertManager._testMode:
            body = '' if alert.getBody() == None else alert.getBody()
            actions.get("mail",
                        "mail:smtp:gmail").sendMail(', '.join(emailAddresses),
                                                    alert.getSubject(),
                                                    alert.getBody(),
                                                    alert.getAttachmentUrls())

        AlertManager._lastEmailedSubject = alert.getSubject()
예제 #3
0
def on_ecobee_thermostat_hold_mode_changed(event):
    hold_mode = scope.items[event.itemName].toString()
    action = actions.get("ecobee", "ecobee:thermostat:account:411921197263")
    if hold_mode is not None and hold_mode != '':
        action.setHold(hold_mode)

        scope.events.sendCommand(event.itemName, '')
        logger.info(u"Changed Ecobee thermostat to '{}'.".format(hold_mode))
예제 #4
0
def SendAndLogMsg(logger, level, message, SendTelegram=False, MailSubject=""):
    """Logs messages and eventually notifies user by Telegram and/or mail"""

    loggerfunction = {
        "ERROR": logger.warn,
        "WARN": logger.warn,
        "INFO": logger.info,
        "DEBUG": logger.debug
    }

    out = str(message)
    log = loggerfunction[level]
    log("{}".format(out))

    if SendTelegram:
        t = actions.get("telegram", "telegram:telegramBot:openhab")
        t.sendTelegram(markus_telegram_chatid, out)

    if MailSubject != "":
        actions.get("mail", "mail:smtp:gmx").sendMail(admin_email, MailSubject,
                                                      message)
예제 #5
0
def volvoHeater(event):
    action = actions.get("volvooncall", "volvooncall:vehicle:v90:V90")
    if action is None:
        volvoHeater.log.info("Actions not found (check thing ID)")
        return
    volvoHeater.log.info(
        "Calling preclimatization action with [{}] status".format(
            event.itemState))
    if event.itemState == ON:
        action.preclimatizationStartCommand()
    elif event.itemState == OFF:
        action.preclimatizationStopCommand()
    else:
        volvoHeater.log.warn("Inavlid state for VoC preclimatization action")
예제 #6
0
def lgtvChannelUpDown(event):
    lgtvChannelUpDown.log.info("LGTV Channel Up-Down [{}]".format(event.event))
    action = actions.get("lgwebos","lgwebos:WebOSTV:tvlivingroom")
    if action is None:
        lgtvChannelUpDown.log.info("LGTV.Channel.UpDn", "Actions not found (check thing ID)")
        return
    cmd = event.receivedCommand
    lgtvChannelUpDown.log.info("LGTV.Channel.UpDn", "Received command [{}]".format(cmd))
    if cmd == 0:
        action.decreaseChannel()
    elif cmd == 1:
        action.increaseChannel()
    else:
        lgtvChannelUpDown.log.warn("Invalid channle up-down command")
예제 #7
0
def send_info(message, logger):
    out = str(message)
    logger.info("[INFO ALERT] {}".format(message))
    NotificationAction.sendNotification(admin_email, out)
    # Mail.sendMail(admin_email, "openHAB Info", out)
    (actions.get("mail", "mail:smtp:gmail").sendMail(admin_email,
                                                     "openHAB Info", out))


# def send_alert(message, logger):
#     out = str(message)
#     night = True if scope.items.BridgeLightSensorState == OFF else False#or scope.items.vTimeOfDay == "BED" else False

#     if not night:
#         logger.warning("[ALERT] {}".format(message))
#         NotificationAction.sendBroadcastNotification(out)
#         # Mail.sendMail(alert_email, "", out)

#         NotificationAction.sendNotification(admin_email, out)
#         # (actions.get("mail", "mail:smtp:gmail").sendMail(admin_email,  "openHAB Info", out))
#     else:
#         send_info(message)
예제 #8
0
def on_ecobee_thermostat_hold_mode_changed(event):
    scope.events.sendCommand(event.itemName, 'OFF')

    action = actions.get("ecobee", "ecobee:thermostat:account:411921197263")
    action.resumeProgram(True)
    logger.info(u"Resumed Ecobee thermostat.")