diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index ca61075d..00000000 Binary files a/.DS_Store and /dev/null differ diff --git a/.gitignore b/.gitignore index 679e0d72..b13cd3bf 100644 --- a/.gitignore +++ b/.gitignore @@ -114,3 +114,5 @@ dmypy.json .pyre/ token.bin PyViCare/__init__.py + +.DS_Store \ No newline at end of file diff --git a/PyViCare/.DS_Store b/PyViCare/.DS_Store deleted file mode 100644 index f6f52240..00000000 Binary files a/PyViCare/.DS_Store and /dev/null differ diff --git a/PyViCare/PyViCare.py b/PyViCare/PyViCare.py index 0eac38ab..4fa2f271 100644 --- a/PyViCare/PyViCare.py +++ b/PyViCare/PyViCare.py @@ -1,6 +1,21 @@ from PyViCare.PyViCareGazBoiler import GazBoiler +# This decorator handles access to underlying JSON properties. +# If the property is not found (KeyError) or the index does not +# exists (IndexError), the requested feature is not supported by +# the device. +def handleNotSupported(func): + def wrapper(*args, **kwargs): + try: + return func(*args, **kwargs) + except KeyError as err: + return "KeyError: " + str(err) + except IndexError as err: + return "IndexError: " + str(err) + return wrapper + # DEPRECATED class ViCareSession(GazBoiler): def dummy(self): - print("done") \ No newline at end of file + print("done") + \ No newline at end of file diff --git a/PyViCare/PyViCareDevice.py b/PyViCare/PyViCareDevice.py index d8c1a5ab..b77a2947 100644 --- a/PyViCare/PyViCareDevice.py +++ b/PyViCare/PyViCareDevice.py @@ -5,6 +5,8 @@ from datetime import datetime, time from PyViCare.PyViCareService import ViCareService from PyViCare.PyViCareCachedService import ViCareCachedService +from PyViCare.PyViCare import handleNotSupported + import traceback logger = logging.getLogger('ViCare') @@ -65,9 +67,9 @@ def setMode(self,mode): # Works for normal, reduced, comfort # active has no action - # exetenral , standby no action + # external, standby no action # holiday, sheculde and unscheduled - # activate, decativate comfort,eco + # activate, decativate comfort, eco """ Set the target temperature for the target program Parameters ---------- @@ -128,107 +130,73 @@ def deactivateProgram(self,program): def deactivateComfort(self): return self.deactivateProgram("comfort") + @handleNotSupported def getMonthSinceLastService(self): - try: - return self.service.getProperty("heating.service.timeBased")["properties"]["activeMonthSinceLastService"]["value"] - except KeyError as err: - return "KeyError: "+str(err) + return self.service.getProperty("heating.service.timeBased")["properties"]["activeMonthSinceLastService"]["value"] + @handleNotSupported def getLastServiceDate(self): - try: - return self.service.getProperty("heating.service.timeBased")["properties"]["lastService"]["value"] - except KeyError as err: - return "KeyError: "+str(err) + return self.service.getProperty("heating.service.timeBased")["properties"]["lastService"]["value"] + @handleNotSupported def getOutsideTemperature(self): - try: - return self.service.getProperty("heating.sensors.temperature.outside")["properties"]["value"]["value"] - except KeyError as err: - return "KeyError: "+str(err) + return self.service.getProperty("heating.sensors.temperature.outside")["properties"]["value"]["value"] + @handleNotSupported def getSupplyTemperature(self): - try: - return self.service.getProperty("heating.circuits." + str(self.service.circuit) + ".sensors.temperature.supply")["properties"]["value"]["value"] - except KeyError as err: - return "KeyError: "+str(err) + return self.service.getProperty("heating.circuits." + str(self.service.circuit) + ".sensors.temperature.supply")["properties"]["value"]["value"] + @handleNotSupported def getRoomTemperature(self): - try: - return self.service.getProperty("heating.circuits." + str(self.service.circuit) + ".sensors.temperature.room")["properties"]["value"]["value"] - except KeyError as err: - return "KeyError: "+str(err) + return self.service.getProperty("heating.circuits." + str(self.service.circuit) + ".sensors.temperature.room")["properties"]["value"]["value"] + @handleNotSupported def getModes(self): - try: - return self.service.getProperty("heating.circuits." + str(self.service.circuit) + ".operating.modes.active")["actions"][0]["fields"][0]["enum"] - except KeyError as err: - return "KeyError: "+str(err) + return self.service.getProperty("heating.circuits." + str(self.service.circuit) + ".operating.modes.active")["actions"][0]["fields"][0]["enum"] + @handleNotSupported def getActiveMode(self): - try: - return self.service.getProperty("heating.circuits." + str(self.service.circuit) + ".operating.modes.active")["properties"]["value"]["value"] - except KeyError as err: - return "KeyError: "+str(err) + return self.service.getProperty("heating.circuits." + str(self.service.circuit) + ".operating.modes.active")["properties"]["value"]["value"] + @handleNotSupported def getHeatingCurveShift(self): - try: - return self.service.getProperty("heating.circuits." + str(self.service.circuit) + ".heating.curve")["properties"]["shift"]["value"] - except KeyError as err: - return "KeyError: "+str(err) + return self.service.getProperty("heating.circuits." + str(self.service.circuit) + ".heating.curve")["properties"]["shift"]["value"] + @handleNotSupported def getHeatingCurveSlope(self): - try: - return self.service.getProperty("heating.circuits." + str(self.service.circuit) + ".heating.curve")["properties"]["slope"]["value"] - except KeyError as err: - return "KeyError: "+str(err) + return self.service.getProperty("heating.circuits." + str(self.service.circuit) + ".heating.curve")["properties"]["slope"]["value"] + @handleNotSupported def getActiveProgram(self): - try: - return self.service.getProperty("heating.circuits." + str(self.service.circuit) + ".operating.programs.active")["properties"]["value"]["value"] - except KeyError as err: - return "KeyError: "+str(err) + return self.service.getProperty("heating.circuits." + str(self.service.circuit) + ".operating.programs.active")["properties"]["value"]["value"] + @handleNotSupported def getPrograms(self): - try: - return self.service.getProperty("heating.circuits." + str(self.service.circuit) + ".operating.programs")["entities"][9]["properties"]["components"] - except KeyError as err: - return "KeyError: "+str(err) + return self.service.getProperty("heating.circuits." + str(self.service.circuit) + ".operating.programs")["entities"][9]["properties"]["components"] + @handleNotSupported def getDesiredTemperatureForProgram(self , program): - try: - return self.service.getProperty("heating.circuits." + str(self.service.circuit) + ".operating.programs."+program)["properties"]["temperature"]["value"] - except KeyError as err: - return "KeyError: "+str(err) + return self.service.getProperty("heating.circuits." + str(self.service.circuit) + ".operating.programs."+program)["properties"]["temperature"]["value"] + @handleNotSupported def getCurrentDesiredTemperature(self): - try: - return self.service.getProperty("heating.circuits." + str(self.service.circuit) + ".operating.programs."+self.getActiveProgram())["properties"]["temperature"]["value"] - except KeyError as err: - return "KeyError: "+str(err) + return self.service.getProperty("heating.circuits." + str(self.service.circuit) + ".operating.programs."+self.getActiveProgram())["properties"]["temperature"]["value"] + @handleNotSupported def getErrorHistory(self): - try: - return self.service.getProperty("heating.errors.history")["properties"]["entries"]["value"] - except KeyError as err: - return "KeyError: "+str(err) + return self.service.getProperty("heating.errors.history")["properties"]["entries"]["value"] + @handleNotSupported def getActiveError(self): - try: - return self.service.getProperty("heating.errors.active")["properties"]["entries"]["value"] - except KeyError as err: - return "KeyError: "+str(err) + return self.service.getProperty("heating.errors.active")["properties"]["entries"]["value"] + @handleNotSupported def getDomesticHotWaterConfiguredTemperature(self): - try: - return self.service.getProperty("heating.dhw.temperature")["properties"]["value"]["value"] - except KeyError as err: - return "KeyError: "+str(err) + return self.service.getProperty("heating.dhw.temperature")["properties"]["value"]["value"] + @handleNotSupported def getDomesticHotWaterConfiguredTemperature2(self): - try: - return self.service.getProperty("heating.dhw.temperature.temp2")["properties"]["value"]["value"] - except KeyError as err: - return "KeyError: "+str(err) + return self.service.getProperty("heating.dhw.temperature.temp2")["properties"]["value"]["value"] def getDomesticHotWaterActiveMode(self): schedule = self.getDomesticHotWaterSchedule() @@ -240,7 +208,7 @@ def getDomesticHotWaterActiveMode(self): try: daySchedule = schedule[VICARE_DAYS[currentDateTime.weekday()]] - except KeyError as err: # no schedule for day configured + except KeyError: # no schedule for day configured return None mode = None @@ -265,30 +233,23 @@ def getDomesticHotWaterDesiredTemperature(self): return None + @handleNotSupported def getDomesticHotWaterStorageTemperature(self): - try: - return self.service.getProperty("heating.dhw.sensors.temperature.hotWaterStorage")["properties"]["value"]["value"] - except KeyError as err: - return "KeyError: "+str(err) + return self.service.getProperty("heating.dhw.sensors.temperature.hotWaterStorage")["properties"]["value"]["value"] + @handleNotSupported def getDomesticHotWaterPumpActive(self): - try: - status = self.service.getProperty("heating.dhw.pumps.primary")["properties"]["status"]["value"] - return status == 'on' - except KeyError as err: - return "KeyError: "+str(err) + status = self.service.getProperty("heating.dhw.pumps.primary")["properties"]["status"]["value"] + return status == 'on' + @handleNotSupported def getDomesticHotWaterMaxTemperature(self): - try: - return self.service.getProperty("heating.dhw.temperature")["actions"][0]["fields"][0]["max"] - except KeyError as err: - return "KeyError: "+str(err) + return self.service.getProperty("heating.dhw.temperature")["actions"][0]["fields"][0]["max"] + @handleNotSupported def getDomesticHotWaterMinTemperature(self): - try: - return self.service.getProperty("heating.dhw.temperature")["actions"][0]["fields"][0]["min"] - except KeyError as err: - return "KeyError: "+str(err) + return self.service.getProperty("heating.dhw.temperature")["actions"][0]["fields"][0]["min"] + """ Set the target temperature for domestic host water Parameters ---------- @@ -317,41 +278,35 @@ def setDomesticHotWaterTemperature(self,temperature): def setDomesticHotWaterTemperature2(self,temperature): return self.service.setProperty("heating.dhw.temperature.temp2","setTargetTemperature","{\"temperature\":"+str(temperature)+"}") + @handleNotSupported def getCirculationPumpActive(self): - try: - status = self.service.getProperty("heating.circuits." + str(self.service.circuit) + ".circulation.pump")["properties"]["status"]["value"] - return status == 'on' - except KeyError as err: - return "KeyError: "+str(err) - - def getHeatingSchedule(self): - try: - properties = self.service.getProperty("heating.circuits." + str(self.service.circuit) + ".heating.schedule")["properties"] - return { - "active": properties["active"]["value"], - "mon": properties["entries"]["value"]["mon"], - "tue": properties["entries"]["value"]["tue"], - "wed": properties["entries"]["value"]["wed"], - "thu": properties["entries"]["value"]["thu"], - "fri": properties["entries"]["value"]["fri"], - "sat": properties["entries"]["value"]["sat"], - "sun": properties["entries"]["value"]["sun"] - } - except KeyError as err: - return "KeyError: "+str(err) + status = self.service.getProperty("heating.circuits." + str(self.service.circuit) + ".circulation.pump")["properties"]["status"]["value"] + return status == 'on' + @handleNotSupported + def getHeatingSchedule(self): + properties = self.service.getProperty("heating.circuits." + str(self.service.circuit) + ".heating.schedule")["properties"] + return { + "active": properties["active"]["value"], + "mon": properties["entries"]["value"]["mon"], + "tue": properties["entries"]["value"]["tue"], + "wed": properties["entries"]["value"]["wed"], + "thu": properties["entries"]["value"]["thu"], + "fri": properties["entries"]["value"]["fri"], + "sat": properties["entries"]["value"]["sat"], + "sun": properties["entries"]["value"]["sun"] + } + + @handleNotSupported def getDomesticHotWaterSchedule(self): - try: - properties = self.service.getProperty("heating.dhw.schedule")["properties"] - return { - "active": properties["active"]["value"], - "mon": properties["entries"]["value"]["mon"], - "tue": properties["entries"]["value"]["tue"], - "wed": properties["entries"]["value"]["wed"], - "thu": properties["entries"]["value"]["thu"], - "fri": properties["entries"]["value"]["fri"], - "sat": properties["entries"]["value"]["sat"], - "sun": properties["entries"]["value"]["sun"] - } - except KeyError as err: - return "KeyError: "+str(err) + properties = self.service.getProperty("heating.dhw.schedule")["properties"] + return { + "active": properties["active"]["value"], + "mon": properties["entries"]["value"]["mon"], + "tue": properties["entries"]["value"]["tue"], + "wed": properties["entries"]["value"]["wed"], + "thu": properties["entries"]["value"]["thu"], + "fri": properties["entries"]["value"]["fri"], + "sat": properties["entries"]["value"]["sat"], + "sun": properties["entries"]["value"]["sun"] + } diff --git a/PyViCare/PyViCareFuelCell.py b/PyViCare/PyViCareFuelCell.py index 44dc76b9..5a1f283a 100644 --- a/PyViCare/PyViCareFuelCell.py +++ b/PyViCare/PyViCareFuelCell.py @@ -1,641 +1,391 @@ from PyViCare.PyViCareGazBoiler import GazBoiler +from PyViCare.PyViCare import handleNotSupported class FuelCell(GazBoiler): + @handleNotSupported def getOperatingPhase(self): - try: - # generation, startup, standby - return self.service.getProperty("heating.fuelCell.operating.phase")["properties"]["value"]["value"] - except KeyError: - return "error" + # generation, startup, standby + return self.service.getProperty("heating.fuelCell.operating.phase")["properties"]["value"]["value"] + @handleNotSupported def getOperatingModesActive(self): - try: - # standby, maintenance, heatControlled, economical, ecological - return self.service.getProperty("heating.fuelCell.operating.modes.active")["properties"]["value"]["value"] - except KeyError: - return "error" + # standby, maintenance, heatControlled, economical, ecological + return self.service.getProperty("heating.fuelCell.operating.modes.active")["properties"]["value"]["value"] + @handleNotSupported def getOperatingModesHeatControlled(self): - try: - # True or False - return self.service.getProperty("heating.fuelCell.operating.modes.heatControlled")["properties"]["active"]["value"] - except KeyError: - return "error" + # True or False + return self.service.getProperty("heating.fuelCell.operating.modes.heatControlled")["properties"]["active"]["value"] + @handleNotSupported def getOperatingModesEcological(self): - try: - # True or False - return self.service.getProperty("heating.fuelCell.operating.modes.ecological")["properties"]["active"]["value"] - except KeyError: - return "error" + # True or False + return self.service.getProperty("heating.fuelCell.operating.modes.ecological")["properties"]["active"]["value"] + @handleNotSupported def getOperatingModesEconomical(self): - try: - # True or False - return self.service.getProperty("heating.fuelCell.operating.modes.economical")["properties"]["active"]["value"] - except KeyError: - return "error" + # True or False + return self.service.getProperty("heating.fuelCell.operating.modes.economical")["properties"]["active"]["value"] + @handleNotSupported def getOperatingModesMaintenance(self): - try: - # True or False - return self.service.getProperty("heating.fuelCell.operating.modes.maintenance")["properties"]["active"]["value"] - except KeyError: - return "error" + # True or False + return self.service.getProperty("heating.fuelCell.operating.modes.maintenance")["properties"]["active"]["value"] + @handleNotSupported def getOperatingModesStandby(self): - try: - # True or False - return self.service.getProperty("heating.fuelCell.operating.modes.standby")["properties"]["active"]["value"] - except KeyError: - return "error" + # True or False + return self.service.getProperty("heating.fuelCell.operating.modes.standby")["properties"]["active"]["value"] + @handleNotSupported def getFuelCellOperationHours(self): - try: - return self.service.getProperty("heating.fuelCell.statistics")["properties"]["operationHours"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.fuelCell.statistics")["properties"]["operationHours"]["value"] + @handleNotSupported def getFuelCellInsertions(self): - try: - return self.service.getProperty("heating.fuelCell.statistics")["properties"]["insertions"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.fuelCell.statistics")["properties"]["insertions"]["value"] + @handleNotSupported def getFuelCellProductionHours(self): - try: - return self.service.getProperty("heating.fuelCell.statistics")["properties"]["productionHours"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.fuelCell.statistics")["properties"]["productionHours"]["value"] + @handleNotSupported def getFuelCellProductionStarts(self): - try: - return self.service.getProperty("heating.fuelCell.statistics")["properties"]["productionStarts"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.fuelCell.statistics")["properties"]["productionStarts"]["value"] + @handleNotSupported def getFuelCellAvailabilityRate(self): - try: - return self.service.getProperty("heating.fuelCell.statistics")["properties"]["availabilityRate"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.fuelCell.statistics")["properties"]["availabilityRate"]["value"] + @handleNotSupported def getCumulativePowerProduced(self): - try: - return self.service.getProperty("heating.power.cumulativeProduced")["properties"]["value"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.power.cumulativeProduced")["properties"]["value"]["value"] + @handleNotSupported def getCumulativePowerSold(self): - try: - return self.service.getProperty("heating.power.cumulativeSold")["properties"]["value"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.power.cumulativeSold")["properties"]["value"]["value"] + @handleNotSupported def getCumulativePowerPurchased(self): - try: - return self.service.getProperty("heating.power.cumulativePurchased")["properties"]["value"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.power.cumulativePurchased")["properties"]["value"]["value"] + @handleNotSupported def getFuelCellReturnTemperature(self): - try: - return self.service.getProperty("heating.fuelCell.sensors.temperature.return")["properties"]["value"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.fuelCell.sensors.temperature.return")["properties"]["value"]["value"] + @handleNotSupported def getReturnTemperature(self): - try: - return self.service.getProperty("heating.sensors.temperature.return")["properties"]["value"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.sensors.temperature.return")["properties"]["value"]["value"] + @handleNotSupported def getPowerProductionCurrent(self): - try: - return self.service.getProperty("heating.power.production.current")["properties"]["value"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.power.production.current")["properties"]["value"]["value"] + @handleNotSupported def getPowerPurchaseCurrent(self): - try: - return self.service.getProperty("heating.power.purchase.current")["properties"]["value"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.power.purchase.current")["properties"]["value"]["value"] + @handleNotSupported def getPowerOutput(self): - try: - return self.service.getProperty("heating.sensors.power.output")["properties"]["value"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.sensors.power.output")["properties"]["value"]["value"] + @handleNotSupported def getPowerProductionDemandCoverageCurrent(self): - try: - return self.service.getProperty("heating.power.production.demandCoverage.current")["properties"]["value"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.power.production.demandCoverage.current")["properties"]["value"]["value"] + @handleNotSupported def getPowerProductionProductionCoverageCurrent(self): - try: - return self.service.getProperty("heating.power.production.productionCoverage.current")["properties"]["value"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.power.production.productionCoverage.current")["properties"]["value"]["value"] + @handleNotSupported def getPowerSoldCurrent(self): - try: - return self.service.getProperty('heating.power.sold.current')['properties']['value']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.power.sold.current')['properties']['value']['value'] + @handleNotSupported def getPowerSoldDays(self): - try: - return self.service.getProperty('heating.power.sold')['properties']['day']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.power.sold')['properties']['day']['value'] + @handleNotSupported def getPowerSoldToday(self): - try: - return self.service.getProperty('heating.power.sold')['properties']['day']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.power.sold')['properties']['day']['value'][0] + @handleNotSupported def getPowerSoldWeeks(self): - try: - return self.service.getProperty('heating.power.sold')['properties']['week']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.power.sold')['properties']['week']['value'] + @handleNotSupported def getPowerSoldThisWeek(self): - try: - return self.service.getProperty('heating.power.sold')['properties']['week']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.power.sold')['properties']['week']['value'][0] + @handleNotSupported def getPowerSoldMonths(self): - try: - return self.service.getProperty('heating.power.sold')['properties']['month']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.power.sold')['properties']['month']['value'] + @handleNotSupported def getPowerSoldThisMonth(self): - try: - return self.service.getProperty('heating.fuelCell.power.production')['properties']['month']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.fuelCell.power.production')['properties']['month']['value'][0] + @handleNotSupported def getPowerSoldYears(self): - try: - return self.service.getProperty('heating.fuelCell.power.production')['properties']['year']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.fuelCell.power.production')['properties']['year']['value'] + @handleNotSupported def getPowerSoldThisYear(self): - try: - return self.service.getProperty('heating.fuelCell.power.production')['properties']['year']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.fuelCell.power.production')['properties']['year']['value'][0] + @handleNotSupported def getPowerProductionDays(self): - try: - return self.service.getProperty('heating.fuelCell.power.production')['properties']['day']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.fuelCell.power.production')['properties']['day']['value'] + @handleNotSupported def getPowerProductionToday(self): - try: - return self.service.getProperty('heating.fuelCell.power.production')['properties']['day']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.fuelCell.power.production')['properties']['day']['value'][0] + @handleNotSupported def getPowerProductionWeeks(self): - try: - return self.service.getProperty('heating.fuelCell.power.production')['properties']['week']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.fuelCell.power.production')['properties']['week']['value'] + @handleNotSupported def getPowerProductionThisWeek(self): - try: - return self.service.getProperty('heating.fuelCell.power.production')['properties']['week']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.fuelCell.power.production')['properties']['week']['value'][0] + @handleNotSupported def getPowerProductionMonths(self): - try: - return self.service.getProperty('heating.fuelCell.power.production')['properties']['month']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.fuelCell.power.production')['properties']['month']['value'] + @handleNotSupported def getPowerProductionThisMonth(self): - try: - return self.service.getProperty('heating.fuelCell.power.production')['properties']['month']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.fuelCell.power.production')['properties']['month']['value'][0] + @handleNotSupported def getPowerProductionYears(self): - try: - return self.service.getProperty('heating.fuelCell.power.production')['properties']['year']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.fuelCell.power.production')['properties']['year']['value'] + @handleNotSupported def getPowerProductionThisYear(self): - try: - return self.service.getProperty('heating.fuelCell.power.production')['properties']['year']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.fuelCell.power.production')['properties']['year']['value'][0] + @handleNotSupported def getPowerConsumptionDays(self): - try: - return self.service.getProperty('heating.power.consumption')['properties']['day']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.power.consumption')['properties']['day']['value'] + @handleNotSupported def getPowerConsumptionToday(self): - try: - return self.service.getProperty('heating.power.consumption')['properties']['day']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.power.consumption')['properties']['day']['value'][0] + @handleNotSupported def getPowerConsumptionWeeks(self): - try: - return self.service.getProperty('heating.power.consumption')['properties']['week']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.power.consumption')['properties']['week']['value'] + @handleNotSupported def getPowerConsumptionThisWeek(self): - try: - return self.service.getProperty('heating.power.consumption')['properties']['week']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.power.consumption')['properties']['week']['value'][0] + @handleNotSupported def getPowerConsumptionMonths(self): - try: - return self.service.getProperty('heating.power.consumption')['properties']['month']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.power.consumption')['properties']['month']['value'] + @handleNotSupported def getPowerConsumptionThisMonth(self): - try: - return self.service.getProperty('heating.power.consumption')['properties']['month']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.power.consumption')['properties']['month']['value'][0] + @handleNotSupported def getPowerConsumptionYears(self): - try: - return self.service.getProperty('heating.power.consumption')['properties']['year']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.power.consumption')['properties']['year']['value'] + @handleNotSupported def getPowerConsumptionThisYear(self): - try: - return self.service.getProperty('heating.power.consumption')['properties']['year']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.power.consumption')['properties']['year']['value'][0] + @handleNotSupported def getPowerConsumptionHeatingDays(self): - try: - return self.service.getProperty('heating.power.consumption.heating')['properties']['day']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.power.consumption.heating')['properties']['day']['value'] + @handleNotSupported def getPowerConsumptionHeatingToday(self): - try: - return self.service.getProperty('heating.power.consumption.heating')['properties']['day']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.power.consumption.heating')['properties']['day']['value'][0] + @handleNotSupported def getPowerConsumptionHeatingWeeks(self): - try: - return self.service.getProperty('heating.power.consumption.heating')['properties']['week']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.power.consumption.heating')['properties']['week']['value'] + @handleNotSupported def getPowerConsumptionHeatingThisWeek(self): - try: - return self.service.getProperty('heating.power.consumption.heating')['properties']['week']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.power.consumption.heating')['properties']['week']['value'][0] + @handleNotSupported def getPowerConsumptionHeatingMonths(self): - try: - return self.service.getProperty('heating.power.consumption.heating')['properties']['month']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.power.consumption.heating')['properties']['month']['value'] + @handleNotSupported def getPowerConsumptionHeatingThisMonth(self): - try: - return self.service.getProperty('heating.power.consumption.heating')['properties']['month']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.power.consumption.heating')['properties']['month']['value'][0] + @handleNotSupported def getPowerConsumptionHeatingYears(self): - try: - return self.service.getProperty('heating.power.consumption.heating')['properties']['year']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.power.consumption.heating')['properties']['year']['value'] + @handleNotSupported def getPowerConsumptionHeatingThisYear(self): - try: - return self.service.getProperty('heating.power.consumption.heating')['properties']['year']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.power.consumption.heating')['properties']['year']['value'][0] + @handleNotSupported def getPowerConsumptionDomesticHotWaterDays(self): - try: - return self.service.getProperty('dhw.power.consumption.dhw')['properties']['day']['value'] - except KeyError: - return "error" + return self.service.getProperty('dhw.power.consumption.dhw')['properties']['day']['value'] + @handleNotSupported def getPowerConsumptionDomesticHotWaterToday(self): - try: - return self.service.getProperty('dhw.power.consumption.dhw')['properties']['day']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('dhw.power.consumption.dhw')['properties']['day']['value'][0] + @handleNotSupported def getPowerConsumptionDomesticHotWaterWeeks(self): - try: - return self.service.getProperty('dhw.power.consumption.dhw')['properties']['week']['value'] - except KeyError: - return "error" + return self.service.getProperty('dhw.power.consumption.dhw')['properties']['week']['value'] + @handleNotSupported def getPowerConsumptionDomesticHotWaterThisWeek(self): - try: - return self.service.getProperty('dhw.power.consumption.dhw')['properties']['week']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('dhw.power.consumption.dhw')['properties']['week']['value'][0] + @handleNotSupported def getPowerConsumptionDomesticHotWaterMonths(self): - try: - return self.service.getProperty('dhw.power.consumption.dhw')['properties']['month']['value'] - except KeyError: - return "error" + return self.service.getProperty('dhw.power.consumption.dhw')['properties']['month']['value'] + @handleNotSupported def getPowerConsumptionDomesticHotWaterThisMonth(self): - try: - return self.service.getProperty('dhw.power.consumption.dhw')['properties']['month']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('dhw.power.consumption.dhw')['properties']['month']['value'][0] + @handleNotSupported def getPowerConsumptionDomesticHotWaterYears(self): - try: - return self.service.getProperty('dhw.power.consumption.dhw')['properties']['year']['value'] - except KeyError: - return "error" + return self.service.getProperty('dhw.power.consumption.dhw')['properties']['year']['value'] + @handleNotSupported def getPowerConsumptionDomesticHotWaterThisYear(self): - try: - return self.service.getProperty('dhw.power.consumption.dhw')['properties']['year']['value'][0] - except KeyError: - return "error" - - def getPowerConsumptionDomesticHotWaterThisWeek(self): - try: - return self.service.getProperty('dhw.power.consumption.dhw')['properties']['week']['value'][0] - except KeyError: - return "error" - - def getPowerConsumptionDomesticHotWaterMonths(self): - try: - return self.service.getProperty('dhw.power.consumption.dhw')['properties']['month']['value'] - except KeyError: - return "error" - - def getPowerConsumptionDomesticHotWaterThisMonth(self): - try: - return self.service.getProperty('dhw.power.consumption.dhw')['properties']['month']['value'][0] - except KeyError: - return "error" - - def getPowerConsumptionDomesticHotWaterYears(self): - try: - return self.service.getProperty('dhw.power.consumption.dhw')['properties']['year']['value'] - except KeyError: - return "error" - - def getPowerConsumptionDomesticHotWaterThisYear(self): - try: - return self.service.getProperty('dhw.power.consumption.dhw')['properties']['year']['value'][0] - except KeyError: - return "error" - - - def getPowerConsumptionHeatingThisWeek(self): - try: - return self.service.getProperty('heating.power.consumption.heating')['properties']['week']['value'][0] - except KeyError: - return "error" - - def getPowerConsumptionHeatingMonths(self): - try: - return self.service.getProperty('heating.power.consumption.heating')['properties']['month']['value'] - except KeyError: - return "error" - - def getPowerConsumptionHeatingThisMonth(self): - try: - return self.service.getProperty('heating.power.consumption.heating')['properties']['month']['value'][0] - except KeyError: - return "error" - - def getPowerConsumptionHeatingYears(self): - try: - return self.service.getProperty('heating.power.consumption.heating')['properties']['year']['value'] - except KeyError: - return "error" - - def getPowerConsumptionHeatingThisYear(self): - try: - return self.service.getProperty('heating.power.consumption.heating')['properties']['year']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('dhw.power.consumption.dhw')['properties']['year']['value'][0] + @handleNotSupported def getGasConsumptionFuelCellDays(self): - try: - return self.service.getProperty('heating.gas.consumption.fuelCell')['properties']['day']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.fuelCell')['properties']['day']['value'] + @handleNotSupported def getGasConsumptionFuelCellToday(self): - try: - return self.service.getProperty('heating.gas.consumption.fuelCell')['properties']['day']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.fuelCell')['properties']['day']['value'][0] + @handleNotSupported def getGasConsumptionFuelCellWeeks(self): - try: - return self.service.getProperty('heating.gas.consumption.fuelCell')['properties']['week']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.fuelCell')['properties']['week']['value'] + @handleNotSupported def getGasConsumptionFuelCellThisWeek(self): - try: - return self.service.getProperty('heating.gas.consumption.fuelCell')['properties']['week']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.fuelCell')['properties']['week']['value'][0] + @handleNotSupported def getGasConsumptionFuelCellMonths(self): - try: - return self.service.getProperty('heating.gas.consumption.fuelCell')['properties']['month']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.fuelCell')['properties']['month']['value'] + @handleNotSupported def getGasConsumptionFuelCellThisMonth(self): - try: - return self.service.getProperty('heating.gas.consumption.fuelCell')['properties']['month']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.fuelCell')['properties']['month']['value'][0] + @handleNotSupported def getGasConsumptionFuelCellYears(self): - try: - return self.service.getProperty('heating.gas.consumption.fuelCell')['properties']['year']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.fuelCell')['properties']['year']['value'] + @handleNotSupported def getGasConsumptionFuelCellThisYear(self): - try: - return self.service.getProperty('heating.gas.consumption.fuelCell')['properties']['year']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.fuelCell')['properties']['year']['value'][0] + @handleNotSupported def getGasConsumptionTotalDays(self): - try: - return self.service.getProperty('heating.gas.consumption.total')['properties']['day']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.total')['properties']['day']['value'] + @handleNotSupported def getGasConsumptionTotalToday(self): - try: - return self.service.getProperty('heating.gas.consumption.total')['properties']['day']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.total')['properties']['day']['value'][0] + @handleNotSupported def getGasConsumptionTotalWeeks(self): - try: - return self.service.getProperty('heating.gas.consumption.total')['properties']['week']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.total')['properties']['week']['value'] + @handleNotSupported def getGasConsumptionTotalThisWeek(self): - try: - return self.service.getProperty('heating.gas.consumption.total')['properties']['week']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.total')['properties']['week']['value'][0] + @handleNotSupported def getGasConsumptionTotalMonths(self): - try: - return self.service.getProperty('heating.gas.consumption.total')['properties']['month']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.total')['properties']['month']['value'] + @handleNotSupported def getGasConsumptionTotalThisMonth(self): - try: - return self.service.getProperty('heating.gas.consumption.total')['properties']['month']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.total')['properties']['month']['value'][0] + @handleNotSupported def getGasConsumptionTotalYears(self): - try: - return self.service.getProperty('heating.gas.consumption.total')['properties']['year']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.total')['properties']['year']['value'] + @handleNotSupported def getGasConsumptionTotalThisYear(self): - try: - return self.service.getProperty('heating.gas.consumption.total')['properties']['year']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.total')['properties']['year']['value'][0] + @handleNotSupported def getPowerProductionCoverageTotalDays(self): - try: - return self.service.getProperty('heating.power.production.productionCoverage.total')['properties']['day']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.power.production.productionCoverage.total')['properties']['day']['value'] + @handleNotSupported def getPowerProductionCoverageTotalToday(self): - try: - return self.service.getProperty('heating.power.production.productionCoverage.total')['properties']['day']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.power.production.productionCoverage.total')['properties']['day']['value'][0] + @handleNotSupported def getPowerProductionCoverageTotalWeeks(self): - try: - return self.service.getProperty('heating.power.production.productionCoverage.total')['properties']['week']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.power.production.productionCoverage.total')['properties']['week']['value'] + @handleNotSupported def getPowerProductionCoverageTotalThisWeek(self): - try: - return self.service.getProperty('heating.power.production.productionCoverage.total')['properties']['week']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.power.production.productionCoverage.total')['properties']['week']['value'][0] + @handleNotSupported def getPowerProductionCoverageTotalMonths(self): - try: - return self.service.getProperty('heating.power.production.productionCoverage.total')['properties']['month']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.power.production.productionCoverage.total')['properties']['month']['value'] + @handleNotSupported def getPowerProductionCoverageTotalThisMonth(self): - try: - return self.service.getProperty('heating.power.production.productionCoverage.total')['properties']['month']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.power.production.productionCoverage.total')['properties']['month']['value'][0] + @handleNotSupported def getPowerProductionCoverageTotalYears(self): - try: - return self.service.getProperty('heating.power.production.productionCoverage.total')['properties']['year']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.power.production.productionCoverage.total')['properties']['year']['value'] + @handleNotSupported def getPowerProductionCoverageTotalThisYear(self): - try: - return self.service.getProperty('heating.power.production.productionCoverage.total')['properties']['year']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.power.production.productionCoverage.total')['properties']['year']['value'][0] + @handleNotSupported def getHeatProductionDays(self): - try: - return self.service.getProperty('heating.heat.production')['properties']['day']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.heat.production')['properties']['day']['value'] + @handleNotSupported def getHeatProductionToday(self): - try: - return self.service.getProperty('heating.heat.production')['properties']['day']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.heat.production')['properties']['day']['value'][0] + @handleNotSupported def getHeatProductionWeeks(self): - try: - return self.service.getProperty('heating.heat.production')['properties']['week']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.heat.production')['properties']['week']['value'] + @handleNotSupported def getHeatProductionThisWeek(self): - try: - return self.service.getProperty('heating.heat.production')['properties']['week']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.heat.production')['properties']['week']['value'][0] + @handleNotSupported def getHeatProductionMonths(self): - try: - return self.service.getProperty('heating.heat.production')['properties']['month']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.heat.production')['properties']['month']['value'] + @handleNotSupported def getHeatProductionThisMonth(self): - try: - return self.service.getProperty('heating.heat.production')['properties']['month']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.heat.production')['properties']['month']['value'][0] + @handleNotSupported def getHeatProductionYears(self): - try: - return self.service.getProperty('heating.heat.production')['properties']['year']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.heat.production')['properties']['year']['value'] + @handleNotSupported def getHeatProductionThisYear(self): - try: - return self.service.getProperty('heating.heat.production')['properties']['year']['value'][0] - except KeyError: - return "error" \ No newline at end of file + return self.service.getProperty('heating.heat.production')['properties']['year']['value'][0] diff --git a/PyViCare/PyViCareGazBoiler.py b/PyViCare/PyViCareGazBoiler.py index 6443da37..f1ca8521 100644 --- a/PyViCare/PyViCareGazBoiler.py +++ b/PyViCare/PyViCareGazBoiler.py @@ -1,178 +1,122 @@ from PyViCare.PyViCareDevice import Device +from PyViCare.PyViCare import handleNotSupported class GazBoiler(Device): + @handleNotSupported def getBurnerActive(self): - try: - return self.service.getProperty("heating.burner")["properties"]["active"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.burner")["properties"]["active"]["value"] + @handleNotSupported def getGasConsumptionHeatingDays(self): - try: - return self.service.getProperty('heating.gas.consumption.heating')['properties']['day']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.heating')['properties']['day']['value'] + @handleNotSupported def getGasConsumptionHeatingToday(self): - try: - return self.service.getProperty('heating.gas.consumption.heating')['properties']['day']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.heating')['properties']['day']['value'][0] + @handleNotSupported def getGasConsumptionHeatingWeeks(self): - try: - return self.service.getProperty('heating.gas.consumption.heating')['properties']['week']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.heating')['properties']['week']['value'] + @handleNotSupported def getGasConsumptionHeatingThisWeek(self): - try: - return self.service.getProperty('heating.gas.consumption.heating')['properties']['week']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.heating')['properties']['week']['value'][0] + @handleNotSupported def getGasConsumptionHeatingMonths(self): - try: - return self.service.getProperty('heating.gas.consumption.heating')['properties']['month']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.heating')['properties']['month']['value'] + @handleNotSupported def getGasConsumptionHeatingThisMonth(self): - try: - return self.service.getProperty('heating.gas.consumption.heating')['properties']['month']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.heating')['properties']['month']['value'][0] + @handleNotSupported def getGasConsumptionHeatingYears(self): - try: - return self.service.getProperty('heating.gas.consumption.heating')['properties']['year']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.heating')['properties']['year']['value'] + @handleNotSupported def getGasConsumptionHeatingThisYear(self): - try: - return self.service.getProperty('heating.gas.consumption.heating')['properties']['year']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.heating')['properties']['year']['value'][0] + @handleNotSupported def getGasConsumptionDomesticHotWaterDays(self): - try: - return self.service.getProperty('heating.gas.consumption.dhw')['properties']['day']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.dhw')['properties']['day']['value'] + @handleNotSupported def getGasConsumptionDomesticHotWaterToday(self): - try: - return self.service.getProperty('heating.gas.consumption.dhw')['properties']['day']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.dhw')['properties']['day']['value'][0] + @handleNotSupported def getGasConsumptionDomesticHotWaterWeeks(self): - try: - return self.service.getProperty('heating.gas.consumption.dhw')['properties']['week']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.dhw')['properties']['week']['value'] + @handleNotSupported def getGasConsumptionDomesticHotWaterThisWeek(self): - try: - return self.service.getProperty('heating.gas.consumption.dhw')['properties']['week']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.dhw')['properties']['week']['value'][0] + @handleNotSupported def getGasConsumptionDomesticHotWaterMonths(self): - try: - return self.service.getProperty('heating.gas.consumption.dhw')['properties']['month']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.dhw')['properties']['month']['value'] + @handleNotSupported def getGasConsumptionDomesticHotWaterThisMonth(self): - try: - return self.service.getProperty('heating.gas.consumption.dhw')['properties']['month']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.dhw')['properties']['month']['value'][0] + @handleNotSupported def getGasConsumptionDomesticHotWaterYears(self): - try: - return self.service.getProperty('heating.gas.consumption.dhw')['properties']['year']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.dhw')['properties']['year']['value'] + @handleNotSupported def getGasConsumptionDomesticHotWaterThisYear(self): - try: - return self.service.getProperty('heating.gas.consumption.dhw')['properties']['year']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.gas.consumption.dhw')['properties']['year']['value'][0] + + @handleNotSupported def getBurnerModulation(self): - try: - return self.service.getProperty('heating.burner.modulation')["properties"]["value"]["value"] - except KeyError: - return "error" - + return self.service.getProperty('heating.burner.modulation')["properties"]["value"]["value"] + @handleNotSupported def getBoilerTemperature(self): - try: - return self.service.getProperty("heating.boiler.sensors.temperature.main")["properties"]["value"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.boiler.sensors.temperature.main")["properties"]["value"]["value"] + @handleNotSupported def getPowerConsumptionDays(self): - try: - return self.service.getProperty('heating.power.consumption.total')['properties']['day']['value'] - except KeyError: - return "error" - + return self.service.getProperty('heating.power.consumption.total')['properties']['day']['value'] + + @handleNotSupported def getPowerConsumptionToday(self): - try: - return self.service.getProperty('heating.power.consumption.total')['properties']['day']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.power.consumption.total')['properties']['day']['value'][0] + @handleNotSupported def getPowerConsumptionWeeks(self): - try: - return self.service.getProperty('heating.power.consumption.total')['properties']['week']['value'] - except KeyError: - return "error" - + return self.service.getProperty('heating.power.consumption.total')['properties']['week']['value'] + + @handleNotSupported def getPowerConsumptionThisWeek(self): - try: - return self.service.getProperty('heating.power.consumption.total')['properties']['week']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.power.consumption.total')['properties']['week']['value'][0] + @handleNotSupported def getPowerConsumptionMonths(self): - try: - return self.service.getProperty('heating.power.consumption.total')['properties']['month']['value'] - except KeyError: - return "error" - + return self.service.getProperty('heating.power.consumption.total')['properties']['month']['value'] + + @handleNotSupported def getPowerConsumptionThisMonth(self): - try: - return self.service.getProperty('heating.power.consumption.total')['properties']['month']['value'][0] - except KeyError: - return "error" + return self.service.getProperty('heating.power.consumption.total')['properties']['month']['value'][0] + @handleNotSupported def getPowerConsumptionYears(self): - try: - return self.service.getProperty('heating.power.consumption.total')['properties']['year']['value'] - except KeyError: - return "error" - + return self.service.getProperty('heating.power.consumption.total')['properties']['year']['value'] + + @handleNotSupported def getPowerConsumptionThisYear(self): - try: - return self.service.getProperty('heating.power.consumption.total')['properties']['year']['value'][0] - except KeyError: - return "error" - + return self.service.getProperty('heating.power.consumption.total')['properties']['year']['value'][0] + + @handleNotSupported def getBurnerHours(self): - try: - return self.service.getProperty('heating.burner.statistics')['properties']['hours']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.burner.statistics')['properties']['hours']['value'] + @handleNotSupported def getBurnerStarts(self): - try: - return self.service.getProperty('heating.burner.statistics')['properties']['starts']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.burner.statistics')['properties']['starts']['value'] + diff --git a/PyViCare/PyViCareHeatPump.py b/PyViCare/PyViCareHeatPump.py index 04b599e0..33d982ed 100644 --- a/PyViCare/PyViCareHeatPump.py +++ b/PyViCare/PyViCareHeatPump.py @@ -3,122 +3,87 @@ import os import logging from PyViCare.PyViCareDevice import Device +from PyViCare.PyViCare import handleNotSupported class HeatPump(Device): + + @handleNotSupported def getCompressorActive(self): - try: - return self.service.getProperty("heating.compressor")["properties"]["active"]["value"] - except KeyError: - return "error" - + return self.service.getProperty("heating.compressor")["properties"]["active"]["value"] + + @handleNotSupported def getReturnTemperature(self): - try: - return self.service.getProperty("heating.sensors.temperature.return")["properties"]["value"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.sensors.temperature.return")["properties"]["value"]["value"] + @handleNotSupported def getCompressorStarts(self): - try: - return self.service.getProperty("heating.compressor.statistics")["properties"]["starts"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.compressor.statistics")["properties"]["starts"]["value"] + @handleNotSupported def getCompressorHours(self): - try: - return self.service.getProperty("heating.compressor.statistics")["properties"]["hours"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.compressor.statistics")["properties"]["hours"]["value"] + @handleNotSupported def getCompressorHoursLoadClass1(self): - try: - return self.service.getProperty("heating.compressors." + str(self.service.circuit) + ".statistics")["properties"]["hoursLoadClassOne"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.compressors." + str(self.service.circuit) + ".statistics")["properties"]["hoursLoadClassOne"]["value"] + @handleNotSupported def getCompressorHoursLoadClass2(self): - try: - return self.service.getProperty("heating.compressors." + str(self.service.circuit) + ".statistics")["properties"]["hoursLoadClassTwo"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.compressors." + str(self.service.circuit) + ".statistics")["properties"]["hoursLoadClassTwo"]["value"] + @handleNotSupported def getCompressorHoursLoadClass3(self): - try: - return self.service.getProperty("heating.compressors." + str(self.service.circuit) + ".statistics")["properties"]["hoursLoadClassThree"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.compressors." + str(self.service.circuit) + ".statistics")["properties"]["hoursLoadClassThree"]["value"] + @handleNotSupported def getCompressorHoursLoadClass4(self): - try: - return self.service.getProperty("heating.compressors." + str(self.service.circuit) + ".statistics")["properties"]["hoursLoadClassFour"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.compressors." + str(self.service.circuit) + ".statistics")["properties"]["hoursLoadClassFour"]["value"] + @handleNotSupported def getCompressorHoursLoadClass5(self): - try: - return self.service.getProperty("heating.compressors." + str(self.service.circuit) + ".statistics")["properties"]["hoursLoadClassFive"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.compressors." + str(self.service.circuit) + ".statistics")["properties"]["hoursLoadClassFive"]["value"] + @handleNotSupported def getSupplyTemperaturePrimaryCircuit(self): - try: - return self.service.getProperty("heating.primaryCircuit.sensors.temperature.supply")["properties"]["value"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.primaryCircuit.sensors.temperature.supply")["properties"]["value"]["value"] + @handleNotSupported def getReturnTemperaturePrimaryCircuit(self): - try: - return self.service.getProperty("heating.primaryCircuit.sensors.temperature.return")["properties"]["value"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.primaryCircuit.sensors.temperature.return")["properties"]["value"]["value"] + @handleNotSupported def getHeatingRodStatusOverall(self): - try: - return self.service.getProperty("heating.heatingRod.status")["properties"]["overall"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.heatingRod.status")["properties"]["overall"]["value"] + @handleNotSupported def getHeatingRodStatusLevel1(self): - try: - return self.service.getProperty("heating.heatingRod.status")["properties"]["level1"]["value"] - except KeyError: - return "error" - + return self.service.getProperty("heating.heatingRod.status")["properties"]["level1"]["value"] + + @handleNotSupported def getHeatingRodStatusLevel2(self): - try: - return self.service.getProperty("heating.heatingRod.status")["properties"]["level2"]["value"] - except KeyError: - return "error" - + return self.service.getProperty("heating.heatingRod.status")["properties"]["level2"]["value"] + + @handleNotSupported def getHeatingRodStatusLevel3(self): - try: - return self.service.getProperty("heating.heatingRod.status")["properties"]["level3"]["value"] - except KeyError: - return "error" - + return self.service.getProperty("heating.heatingRod.status")["properties"]["level3"]["value"] + + @handleNotSupported def getCompressorPower(self): """Get compressor power percentage""" - try: - return self.service.getProperty("heating.compressors." + str(self.service.circuit) + ".sensors.power")["properties"]["value"]["value"] - except KeyError: - return "error" - + return self.service.getProperty("heating.compressors." + str(self.service.circuit) + ".sensors.power")["properties"]["value"]["value"] + + @handleNotSupported def getExpansionValve(self): """Get expansion valve percentage""" - try: - return self.service.getProperty("heating.sensors.valve.expansion")["properties"]["value"]["value"] - except KeyError: - return "error" - + return self.service.getProperty("heating.sensors.valve.expansion")["properties"]["value"]["value"] + + @handleNotSupported def getSuctionGasPressure(self): """Get suction gas pressure in bar""" - try: - return self.service.getProperty("heating.sensors.pressure.suctionGas")["properties"]["value"]["value"] - except KeyError: - return "error" - + return self.service.getProperty("heating.sensors.pressure.suctionGas")["properties"]["value"]["value"] + + @handleNotSupported def getHotGasPressure(self): """Get hot gas pressure in bar""" - try: - return self.service.getProperty("heating.sensors.pressure.hotGas")["properties"]["value"]["value"] - except KeyError: - return "error" + return self.service.getProperty("heating.sensors.pressure.hotGas")["properties"]["value"]["value"] + \ No newline at end of file diff --git a/PyViCare/PyViCareOilBoiler.py b/PyViCare/PyViCareOilBoiler.py index db0415b8..a07c6a1b 100644 --- a/PyViCare/PyViCareOilBoiler.py +++ b/PyViCare/PyViCareOilBoiler.py @@ -1,33 +1,24 @@ from PyViCare.PyViCareDevice import Device +from PyViCare.PyViCare import handleNotSupported class OilBoiler(Device): + @handleNotSupported def getBurnerActive(self): - try: - return self.service.getProperty("heating.burner")["properties"]["active"]["value"] - except KeyError: - return "error" - + return self.service.getProperty("heating.burner")["properties"]["active"]["value"] + + @handleNotSupported def getBurnerModulation(self): - try: - return self.service.getProperty('heating.burner.modulation')["properties"]["value"]["value"] - except KeyError: - return "error" - + return self.service.getProperty('heating.burner.modulation')["properties"]["value"]["value"] + + @handleNotSupported def getBoilerTemperature(self): - try: - return self.service.getProperty("heating.boiler.sensors.temperature.main")["properties"]["value"]["value"] - except KeyError: - return "error" - + return self.service.getProperty("heating.boiler.sensors.temperature.main")["properties"]["value"]["value"] + + @handleNotSupported def getBurnerHours(self): - try: - return self.service.getProperty('heating.burner.statistics')['properties']['hours']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.burner.statistics')['properties']['hours']['value'] + @handleNotSupported def getBurnerStarts(self): - try: - return self.service.getProperty('heating.burner.statistics')['properties']['starts']['value'] - except KeyError: - return "error" + return self.service.getProperty('heating.burner.statistics')['properties']['starts']['value'] diff --git a/PyViCare/PyViCareService.py b/PyViCare/PyViCareService.py index aa3c891d..078cf5f1 100644 --- a/PyViCare/PyViCareService.py +++ b/PyViCare/PyViCareService.py @@ -107,7 +107,7 @@ def __getNewToken(self, username, password,token_file=None): oauth sessions object """ oauth = OAuth2Session(client_id, redirect_uri=redirect_uri,scope=viessmann_scope) - authorization_url, state = oauth.authorization_url(authorizeURL) + authorization_url, _ = oauth.authorization_url(authorizeURL) logger.debug("Auth URL is: "+authorization_url) @@ -120,7 +120,7 @@ def __getNewToken(self, username, password,token_file=None): #capture the error, which contains the code the authorization code and put this in to codestring codestring = "{0}".format(str(e.args[0])).encode("utf-8") codestring = str(codestring) - match = re.search("code\=(.*)\&",codestring) + match = re.search("code=(.*)&",codestring) codestring=match.group(1) logger.debug("Codestring : "+codestring) oauth.fetch_token(token_url, client_secret=client_secret,authorization_response=authorization_url,code=codestring) @@ -166,7 +166,7 @@ def __get(self,url): self.renewToken() r = self.oauth.get(url).json() return r - except TokenExpiredError as e: + except TokenExpiredError: self.renewToken() return self.__get(url) @@ -195,22 +195,27 @@ def __post(self,url,data): return r except JSONDecodeError: if j.status_code == 204: - return json.loads("{\"statusCode\": 204, \"error\": \"None\", \"message\": \"SUCCESS\"}") + return {"statusCode": 204, "error": "None", "message": "SUCCESS"} else: - return json.loads("{\"statusCode\":"+j.status_code+", \"error\": \"Unknown\", \"message\": \"UNKNOWN\"}") - except TokenExpiredError as e: + return {"statusCode": j.status_code, "error": "Unknown", "message": "UNKNOWN"} + except TokenExpiredError: self.renewToken() return self.__post(url,data) def _serializeToken(self,oauth,token_file): binary_file = open(token_file,mode='wb') - s_token = pickle.dump(oauth,binary_file) - binary_file.close() + try: + pickle.dump(oauth,binary_file) + finally: + binary_file.close() def _deserializeToken(self,token_file): binary_file = open(token_file,mode='rb') - s_token = pickle.load(binary_file) - return s_token + try: + s_token = pickle.load(binary_file) + return s_token + finally: + binary_file.close() def _getInstallations(self): self.installations = self.__get(apiURLBase+"/general-management/installations?expanded=true&") diff --git a/PyViCare/__init__.py b/PyViCare/__init__.py index 37f7a5c6..7188550d 100644 --- a/PyViCare/__init__.py +++ b/PyViCare/__init__.py @@ -1 +1 @@ -__all__ = ['PyViCareService''PyViCareDevice','PyViCareGazBoiler','PyViCareHeatPump','PyViCareCachedService','PyViCareOilBoiler'] \ No newline at end of file +__all__ = ['PyViCareService','PyViCareDevice','PyViCareGazBoiler','PyViCareHeatPump','PyViCareCachedService','PyViCareOilBoiler'] \ No newline at end of file diff --git a/README.md b/README.md index 16ee32fc..d71b1cff 100644 --- a/README.md +++ b/README.md @@ -8,24 +8,25 @@ A few nice feature removed from the app are available though the API (Comfort an ## Version 0.1.0 Note that the version 0.1.0 DOES BREAK a few things. -ViCareSession is deprecated (but you can still import it using f"rom PyViCare.PyViCare import ViCareSession"). +ViCareSession is deprecated (but you can still import it using `from PyViCare.PyViCare import ViCareSession`). You can now use the following objects: -``` +```python from PyViCare.PyViCareDevice import Device # generic device from PyViCare.PyViCareGazBoiler import GazBoiler # gaz boiler from PyViCare.PyViCareHeatPump import HeatPump # heat pump ``` +## Device Features / Errors + +Depending on the device, some features are not available/supported. This results in a response of `error` if the dedicated method is called. This is (mostly) not a bug, but a limitation of the device itself. + ## Basic usage Simple example: -``` +```python import sys import logging sys.path.insert(0, 'PyViCare') -from PyViCare.PyViCareDevice import Device from PyViCare.PyViCareGazBoiler import GazBoiler -from PyViCare.PyViCareService import ViCareService -from PyViCare.PyViCare import ViCareSession t=GazBoiler("email@domain","password","token.save") print(t.getDomesticHotWaterConfiguredTemperature()) @@ -61,12 +62,12 @@ Follow these steps to access the API in Postman: 1. Create an access token in the `Authorization` tab with type `OAuth 2.0` and following inputs: - - Client id: 79742319e39245de5f91d15ff4cac2a8 - - Secret id: 8ad97aceb92c5892e102b093c7c083fa - - Callback url: vicare://oauth-callback/everest - - Auth url: https://iam.viessmann.com/idp/v1/authorize - - Access token url: https://iam.viessmann.com/idp/v1/token - - Scope: openid + - Client id: `79742319e39245de5f91d15ff4cac2a8` + - Secret id: `8ad97aceb92c5892e102b093c7c083fa` + - Callback url: `vicare://oauth-callback/everest` + - Auth url: `https://iam.viessmann.com/idp/v1/authorize` + - Access token url: `https://iam.viessmann.com/idp/v1/token` + - Scope: `openid` A login popup will open. Enter your ViCare username and password. @@ -82,5 +83,6 @@ Follow these steps to access the API in Postman: `https://api.viessmann-platform.io/operational-data/v1/installations/{installationId}/gateways/{gatewaySerial}/devices/0/features` ## Types of heatings -- Use ViCareSession for gas heatings -- Use ViCareHeatPumpSession for heat pumps +- Use `GazBoiler` for gas heatings +- Use `HeatPump` for heat pumps +- Use `FuelCell` for fuel cells