From 7ab48d968e1287a14df1beea02d7b04ebbef1a01 Mon Sep 17 00:00:00 2001 From: Jacob McSwain Date: Mon, 3 Feb 2020 15:00:20 -0600 Subject: [PATCH] Adapt @therealryanbonham's PR (#79) This removes the formatting portion, which should have been a separate PR --- custom_components/badnest/api.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/custom_components/badnest/api.py b/custom_components/badnest/api.py index aa495f4..6695414 100644 --- a/custom_components/badnest/api.py +++ b/custom_components/badnest/api.py @@ -166,6 +166,17 @@ class NestAPI(): self.login() return self.get_devices() + + def _map_nest_protect_state(self, value): + if value == 0: + return "Ok" + elif value == 1 or value == 2: + return "Warning" + elif value == 3: + return "Emergency" + else: + return "Unknown" + def update(self): try: # To get friendly names @@ -270,11 +281,11 @@ class NestAPI(): f' ({sensor_data["description"]})' self.device_data[sn]['name'] += ' Protect' self.device_data[sn]['co_status'] = \ - sensor_data['co_status'] + self._map_nest_protect_state(sensor_data['co_status']) self.device_data[sn]['smoke_status'] = \ - sensor_data['smoke_status'] + self._map_nest_protect_state(sensor_data['smoke_status']) self.device_data[sn]['battery_health_state'] = \ - sensor_data['battery_health_state'] + self._map_nest_protect_state(sensor_data['battery_health_state']) # Temperature sensors elif bucket["object_key"].startswith( f"kryptonite.{sn}"):