From e40a179de621a4eb0ccea7e3cb8ec571f554c608 Mon Sep 17 00:00:00 2001 From: Stephen Papierski Date: Sat, 13 Feb 2021 00:18:56 -0700 Subject: [PATCH] Added a pellet level sensor --- custom_components/traeger/sensor.py | 54 +++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/custom_components/traeger/sensor.py b/custom_components/traeger/sensor.py index b6ebe48..5cf62de 100644 --- a/custom_components/traeger/sensor.py +++ b/custom_components/traeger/sensor.py @@ -149,3 +149,57 @@ def state(self): @property def unit_of_measurement(self): return self.grill_units + + +class PelletSensor(IntegrationBlueprintEntity): + """Traeger Pellet Sensor class.""" + + def __init__(self, client, grill_id, value): + self.grill_id = grill_id + self.client = client + self.value = value + self.grill_state = None + self.grill_units = None + + # Tell the Traeger client to call grill_update() when it gets an update + self.client.set_callback_for_grill(self.grill_id, self.grill_update) + + def grill_update(self): + self.grill_state = self.client.get_state_for_device(self.grill_id) + self.grill_units = self.client.get_units_for_device(self.grill_id) + + # Tell HA we have an update + self.schedule_update_ha_state() + + # Generic Properties + # @property + # def available(self): + # """Reports unavailable when the grill is powered off""" + # if self.grill_state is None: + # return False + # else: + # return True if self.grill_state["connected"] == True else False + + @property + def name(self): + """Return the name of the sensor.""" + return f"{self.value.replace('_',' ').title()}" + + @property + def unique_id(self): + return f"{self.grill_id}-{self.value}" + + @property + def icon(self): + return "mdi:gauge" + + # Sensor Properties + @property + def state(self): + if self.grill_state is None: + return 0 + return self.grill_state[self.value] + + @property + def unit_of_measurement(self): + return "%"