def getText(self, warnings: List[DwdData], seperator: str = "<br>"): text = "" isFirst = True for x in warnings: if isFirst is False: text = text + seperator warnImg: str = "" details = "" if (self.detailLevel.showIcon): # can also be multiple entries, sometime they use ',' sometime ';' n = x.eventGroup.replace(",", ";") splits = n.split(";") warnColor = x.eventColor warnColor = warnColor.replace(" ", ",") for split in splits: icn = DwdIcons.getByName(split) if not icn: Domoticz.Error( "did not got an image for {}".format(split)) else: dscr = "" if self.detailLevel.showDetails: dscr = self.extractDescription(x.description) warnImg = ( "{}<img style='border: solid rgb({});'" "height='20' src='{}' title='{:%a %d %H:%M}-{:%a %H:%M} {}'/>" ).format(warnImg, warnColor, icn.getUrl(), x.startTime, x.endTime, dscr) else: # so no icon but need to put details there details = " " + self.extractDescription(x.description) text = text + warnImg + x.getSummary() + details isFirst = False if isBlank(text): # TODO just for Testing remove later if self.test: # icn = DwdIcons.RAIN icn = random.choice(list(DwdIcons)) cl = DwdAlertColor.getBySeverity(random.choice(list(Severity))) warnColor = cl text = "No Alert <img style='border: solid {};' height='20' src='{}' />".format( warnColor.getColorAsHexString(), icn.getUrl()) else: text = "No Alert" return text
def getSummary(self, seperator: str = "<br>") -> str: s: str = "" isFirst = True for x in self.immediateWarnings: s = s + x.getSummary(seperator=seperator) if isFirst is False: s = s + seperator isFirst = False for x in self.futureWarnings: s = s + x.getSummary(seperator=seperator) if isFirst is False: s = s + seperator isFirst = False if isBlank(s): s = "No Data" return s
def getByName(cls, aName: str): # cls here is the enumeration if isBlank(aName): return None return cls.__getattr__(aName.upper()) # type: ignore
def onStart(self): Domoticz.Log("onStart called") if blzHelperInterface.containsDebug(Parameters["Mode6"]): self.debug = True Domoticz.Debugging(1) DumpConfigToLog() else: Domoticz.Debugging(0) self.test = blzHelperInterface.containsTest(Parameters["Mode6"]) # check polling interval parameter try: temp = int(Parameters["Mode4"]) except: Domoticz.Error("Invalid polling interval parameter") else: if temp < POLL_THRESHOLD_MIN_MINUTES: temp = POLL_THRESHOLD_MIN_MINUTES # minimum polling interval Domoticz.Error( "Specified polling interval too short: changed to {}". format(POLL_THRESHOLD_MIN_MINUTES)) elif temp > POLL_THRESHOLD_MAX_MINUTES: temp = POLL_THRESHOLD_MAX_MINUTES # maximum polling interval is 1 hour Domoticz.Error( "Specified polling interval too long: changed to {} hour". format(POLL_THRESHOLD_MAX_MINUTES)) self.pollinterval = temp * 60 Domoticz.Log("Using polling interval of {} seconds".format( str(self.pollinterval))) self.warncellId = Parameters["Mode1"] self.region = Parameters["Mode2"] if blzHelperInterface.isBlank( self.warncellId) or blzHelperInterface.isBlank(self.region): Domoticz.Error( "No warncellId / regionType set - please update setting.") raise ValueError("warncellId and regionType must be given.") # check detail level if blzHelperInterface.isBlank(Parameters["Mode3"]): Domoticz.Log("No Detail level defined use default: {}".format( DEFAULT_DETAIL_LEVEL.name)) self.detailLevel: DwdDetailLevel = DEFAULT_DETAIL_LEVEL else: self.detailLevel: DwdDetailLevel = DwdDetailLevel.getByName( Parameters["Mode3"]) Domoticz.Debug("Use detail level: {}".format(self.detailLevel.name)) # TODO check images # TODO create device now and feature # Check if devices need to be created createDevices() # init with empty data updateDevice(UNIT_NOW_SWITCH_IDX, 0, "No Data", "DWD" + UNIT_NOW_NAME_SUFFIX) updateDevice(UNIT_FUTURE_SWITCH_IDX, 0, "No Data", "DWD" + UNIT_FUTURE_NAME_SUFFIX) self.regionType = RegionType.getByName(self.region) self.defName = None # init and check dwd self.dwd = Dwd(self.warncellId, self.regionType, self.detailLevel, self.debug, self.test) Domoticz.Debug("check if configuration fits...") if self.dwd.doesWarnCellExist(): Domoticz.Log("DWD Configuration allright - continue") # show name n = self.dwd.getDeviceName() updateDevice(UNIT_NOW_SWITCH_IDX, 0, "No Data", n + UNIT_NOW_NAME_SUFFIX) updateDevice(UNIT_FUTURE_SWITCH_IDX, 0, "No Data", n + UNIT_FUTURE_NAME_SUFFIX) else: Domoticz.Error("Please verify configuration and look into logs.") msg: str = "Wrong Configuration" # check for error detail if (self.dwd.hasErrorX): msg = self.dwd.getErrorMsg() updateDevice( UNIT_NOW_SWITCH_IDX, 0, msg, "DWD" + UNIT_NOW_NAME_SUFFIX, ) updateDevice( UNIT_FUTURE_SWITCH_IDX, 0, msg, "DWD" + UNIT_FUTURE_NAME_SUFFIX, ) # TODO auf NONE setzen oder nicht? # self.dwd = None if self.debug is True and self.dwd is not None: self.dwd.dumpConfig() else: Domoticz.Debug("dwd is None")