diff --git a/decora_wifi/base_model.py b/decora_wifi/base_model.py index a06fccf..5cadf16 100644 --- a/decora_wifi/base_model.py +++ b/decora_wifi/base_model.py @@ -1,11 +1,12 @@ class BaseModel(object): """ This is the base class for all Leviton REST models """ - def __init__(self, session, model_id=None): + def __init__(self, session, model_id=None, panel_id=None): """Set up fields...""" self.data = {} self._session = session self._id = model_id + self._panel_id = panel_id def __str__(self): """Output the wrapped data dictionary.""" diff --git a/decora_wifi/models/residence.py b/decora_wifi/models/residence.py index 8931723..0d6b4c2 100644 --- a/decora_wifi/models/residence.py +++ b/decora_wifi/models/residence.py @@ -369,6 +369,70 @@ def refresh(self): self.data.update(result) return self + def get_energy_consumption_for_day(self, day, timezone=None, attribs=None): + if attribs is None: + attribs = {} + attribs["id"] = str(self._id) + attribs["localTimezone"] = timezone + attribs["theDay"] = day + api = "/Residences/energyConsumptionForDay" + items = self._session.call_api(api, attribs, 'get') + + result = [] + if items is not None: + for hour in items: + result.append(hour) + #{'theHour': 17, 'energyConsumption': 0.09} + return result + + def get_energy_consumption_for_week(self, week, timezone=None, attribs=None): + if attribs is None: + attribs = {} + attribs["id"] = str(self._id) + attribs["localTimezone"] = timezone + attribs["theWeek"] = week + api = "/Residences/energyConsumptionForWeek" + items = self._session.call_api(api, attribs, 'get') + + result = [] + if items is not None: + for day in items: + result.append(day) + #{'theDay': '2021-08-04T00:00:00.000Z', 'energyConsumption': 34.35} + return result + + def get_energy_consumption_for_month(self, month, timezone=None, attribs=None): + if attribs is None: + attribs = {} + attribs["id"] = str(self._id) + attribs["localTimezone"] = timezone + attribs["theMonth"] = month + api = "/Residences/energyConsumptionForMonth" + items = self._session.call_api(api, attribs, 'get') + + result = [] + if items is not None: + for week in items: + result.append(week) + #{'theDay': '2021-08-04T00:00:00.000Z', 'energyConsumption': 34.35} + return result + + def get_energy_consumption_for_year(self, year, timezone=None, attribs=None): + if attribs is None: + attribs = {} + attribs["id"] = str(self._id) + attribs["localTimezone"] = timezone + attribs["theYear"] = year + api = "/Residences/energyConsumptionForYear" + items = self._session.call_api(api, attribs, 'get') + + result = [] + if items is not None: + for month in items: + result.append(month) + #{'theMonth': 7, 'theYear': 2021, 'energyConsumption': 498.28} + return result + def get_invitations(self, attribs=None): if attribs is None: attribs = {} diff --git a/decora_wifi/models/residential_breaker.py b/decora_wifi/models/residential_breaker.py index 69e6a65..8de4357 100644 --- a/decora_wifi/models/residential_breaker.py +++ b/decora_wifi/models/residential_breaker.py @@ -9,8 +9,8 @@ class ResidentialBreaker(BaseModel): - def __init__(self, session, model_id=None): - super(ResidentialBreaker, self).__init__(session, model_id) + def __init__(self, session, model_id=None, panel_id=None): + super(ResidentialBreaker, self).__init__(session, model_id, panel_id) @classmethod def count(cls, session, attribs=None): @@ -83,6 +83,74 @@ def refresh(self): self.data.update(result) return self + def get_energy_consumption_for_day(self, day, timezone, attribs=None): + if attribs is None: + attribs = {} + attribs["residentialBreakerPanelId"] = str(self._panel_id) + attribs["id"] = str(self._id) + attribs["theDay"] = day + attribs["localTimezone"] = timezone + api = "/ResidentialBreakers/energyConsumptionForDay" + items = self._session.call_api(api, attribs, 'get') + + result = [] + if items is not None: + for hour in items: + result.append(hour) + #{'residentialBreakerPanelId': 'LDATA-ABCDE-12345-FGHIJ', 'residentialBreakerId': '4C4512345678', 'position': 6, 'theHour': 21, 'energyConsumption': 11.62} + return result + + def get_energy_consumption_for_week(self, week, timezone, attribs=None): + if attribs is None: + attribs = {} + attribs["residentialBreakerPanelId"] = str(self._panel_id) + attribs["id"] = str(self._id) + attribs["theWeek"] = week + attribs["localTimezone"] = timezone + api = "/ResidentialBreakers/energyConsumptionForWeek" + items = self._session.call_api(api, attribs, 'get') + + result = [] + if items is not None: + for day in items: + result.append(day) + #{'residentialBreakerPanelId': 'LDATA-ABCDE-12345-FGHIJ', 'residentialBreakerId': '4C4512345678', 'position': 10, 'theDay': '2021-08-02T00:00:00.000Z', 'energyConsumption': 13.33} + return result + + def get_energy_consumption_for_month(self, month, timezone, attribs=None): + if attribs is None: + attribs = {} + attribs["residentialBreakerPanelId"] = str(self._panel_id) + attribs["id"] = str(self._id) + attribs["theMonth"] = month + attribs["localTimezone"] = timezone + api = "/ResidentialBreakers/energyConsumptionForMonth" + items = self._session.call_api(api, attribs, 'get') + + result = [] + if items is not None: + for week in items: + result.append(week) + #{'residentialBreakerPanelId': 'LDATA-ABCDE-12345-FGHIJ', 'residentialBreakerId': '4C4512345678', 'position': 6, 'theDay': '2021-08-13T00:00:00.000Z', 'energyConsumption': 47.07} + return result + + def get_energy_consumption_for_year(self, year, timezone, attribs=None): + if attribs is None: + attribs = {} + attribs["residentialBreakerPanelId"] = str(self._panel_id) + attribs["id"] = str(self._id) + attribs["theYear"] = year + attribs["localTimezone"] = timezone + api = "/ResidentialBreakers/energyConsumptionForYear" + items = self._session.call_api(api, attribs, 'get') + + result = [] + if items is not None: + for month in items: + result.append(month) + #{'residentialBreakerPanelId': 'LDATA-ABCDE-12345-FGHIJ', 'residentialBreakerId': '4C4512345678', 'position': 10, 'theMonth': 1, 'theYear': 2021, 'energyConsumption': 401.24} + return result + def get_residential_breaker_panel(self, attribs=None): if attribs is None: attribs = {} diff --git a/decora_wifi/models/residential_breaker_panel.py b/decora_wifi/models/residential_breaker_panel.py index e93a541..dc7d16b 100644 --- a/decora_wifi/models/residential_breaker_panel.py +++ b/decora_wifi/models/residential_breaker_panel.py @@ -142,6 +142,70 @@ def get_access_tokens(self, attribs=None): api = "/ResidentialBreakerPanels/{0}/accessTokens".format(self._id) return self._session.call_api(api, attribs, 'get') + def get_energy_consumption_for_day(self, attribs=None): + if attribs is None: + attribs = {} + attribs["id"] = str(self._id) + attribs["theDay"] = "2021-08-13T00:00:00.000Z" + attribs["localTimezone"] = "America/New_York" + api = "/ResidentialBreakerPanels/energyConsumptionForDay" + items = self._session.call_api(api, attribs, 'get') + + result = [] + if items is not None: + for hour in items: + result.append(hour) + #{'residentialBreakerPanelId': 'LDATA-ASE89-45KYJ-CFDNL', 'theHour': 20, 'energyConsumption': 11.69} + return result + + def get_energy_consumption_for_week(self, week, timezone, attribs=None): + if attribs is None: + attribs = {} + attribs["id"] = str(self._id) + attribs["theWeek"] = week + attribs["localTimezone"] = timezone + api = "/ResidentialBreakerPanels/energyConsumptionForWeek" + items = self._session.call_api(api, attribs, 'get') + + result = [] + if items is not None: + for day in items: + result.append(day) + #{'residentialBreakerPanelId': 'LDATA-ASE89-45KYJ-CFDNL', 'theDay': '2021-08-06T00:00:00.000Z', 'energyConsumption': 16.33} + return result + + def get_energy_consumption_for_month(self, month, timezone, attribs=None): + if attribs is None: + attribs = {} + attribs["id"] = str(self._id) + attribs["theMonth"] = month + attribs["localTimezone"] = timezone + api = "/ResidentialBreakerPanels/energyConsumptionForMonth" + items = self._session.call_api(api, attribs, 'get') + + result = [] + if items is not None: + for week in items: + result.append(week) + #{'residentialBreakerPanelId': 'LDATA-ASE89-45KYJ-CFDNL', 'theDay': '2021-08-11T00:00:00.000Z', 'energyConsumption': 26.19} + return result + + def get_energy_consumption_for_year(self, year, timezone, attribs=None): + if attribs is None: + attribs = {} + attribs["id"] = str(self._id) + attribs["theYear"] = year + attribs["localTimezone"] = timezone + api = "/ResidentialBreakerPanels/energyConsumptionForYear" + items = self._session.call_api(api, attribs, 'get') + + result = [] + if items is not None: + for month in items: + result.append(month) + #{'residentialBreakerPanelId': 'LDATA-ASE89-45KYJ-CFDNL', 'theMonth': 5, 'theYear': 2021, 'energyConsumption': 581.8} + return result + def get_residence(self, attribs=None): if attribs is None: attribs = {} @@ -163,7 +227,7 @@ def get_residential_breakers(self, attribs=None): result = [] if items is not None: for data in items: - model = ResidentialBreaker(self._session, data['id']) + model = ResidentialBreaker(self._session, data['id'], self._id) model.data = data result.append(model) return result