Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Commit

Permalink
Added propane sensor support for iGrill v3
Browse files Browse the repository at this point in the history
  • Loading branch information
apop880 committed Oct 14, 2020
1 parent 93e6093 commit e6522bf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
17 changes: 14 additions & 3 deletions igrill.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ class UUIDS(object):
PROBE4_TEMPERATURE = btle.UUID('06ef0008-2e06-4b79-9e33-fce2c42805ec')
PROBE4_THRESHOLD = btle.UUID('06ef0009-2e06-4b79-9e33-fce2c42805ec')
HEATING_ELEMENTS = btle.UUID('6c91000a-58dc-41c7-943f-518b278ceaaa')
PROPANE_LEVEL = btle.UUID('f5d40001-3548-4c22-9947-f3673fce3cd9')


class IDevicePeripheral(btle.Peripheral):
encryption_key = None
btle_lock = threading.Lock()
has_battery = None
has_heating_element = None
has_propane_sensor = None

def __init__(self, address, name, num_probes, has_battery=True, has_heating_element=False):
def __init__(self, address, name, num_probes, has_battery=True, has_heating_element=False, has_propane_sensor=False):
"""
Connects to the device given by address performing necessary authentication
"""
Expand All @@ -49,6 +51,7 @@ def __init__(self, address, name, num_probes, has_battery=True, has_heating_elem
self.name = name
self.has_battery = has_battery
self.has_heating_element = has_heating_element
self.has_propane_sensor = has_propane_sensor
# iDevice devices require bonding. I don't think this will give us bonding
# if no bonding exists, so please use bluetoothctl to create a bond first
self.setSecurityLevel('medium')
Expand All @@ -64,6 +67,10 @@ def __init__(self, address, name, num_probes, has_battery=True, has_heating_elem
if has_heating_element:
self.heating_elements = self.characteristic(UUIDS.HEATING_ELEMENTS)

# Set handle for reading propane level
if has_propane_sensor:
self.propane_level = self.characteristic(UUIDS.PROPANE_LEVEL)

# authenticate with iDevices custom challenge/response protocol
if not self.authenticate():
raise RuntimeError('Unable to authenticate with device')
Expand Down Expand Up @@ -124,6 +131,9 @@ def read_battery(self):
def read_heating_elements(self):
return bytearray(self.heating_elements.read()) if self.has_heating_element else None

def read_propane_level(self):
return float(bytearray(self.propane_level.read())[0])*25 if self.has_propane_sensor else None

def read_temperature(self, publish_empty, missing_value):
empty = False if not publish_empty else missing_value
temps = {1: False, 2: False, 3: False, 4: False}
Expand Down Expand Up @@ -163,7 +173,7 @@ class IGrillV3Peripheral(IDevicePeripheral):

def __init__(self, address, name='igrill_v3', num_probes=4):
logging.debug("Created new device with name {}".format(name))
IDevicePeripheral.__init__(self, address, name, num_probes)
IDevicePeripheral.__init__(self, address, name, num_probes, has_propane_sensor=True)


class Pulse2000Peripheral(IDevicePeripheral):
Expand Down Expand Up @@ -215,7 +225,8 @@ def run(self):
temperature = device.read_temperature(self.publish_missing_probes, self.missing_probe_value)
battery = device.read_battery()
heating_element = device.read_heating_elements()
utils.publish(temperature, battery, heating_element, self.mqtt_client, self.topic, device.name)
propane_level = device.read_propane_level()
utils.publish(temperature, battery, heating_element, propane_level, self.mqtt_client, self.topic, device.name)
logging.debug("Published temp: {} and battery: {} to topic {}/{}".format(temperature, battery, self.topic, device.name))
logging.debug("Sleeping for {} seconds".format(self.interval))
time.sleep(self.interval)
Expand Down
4 changes: 3 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def mqtt_init(mqtt_config):
return mqtt_client


def publish(temperatures, battery, heating_element, client, base_topic, device_name):
def publish(temperatures, battery, heating_element, propane_level, client, base_topic, device_name):
for i in range(1, 5):
if temperatures[i]:
client.publish("{0}/{1}/probe{2}".format(base_topic, device_name, i), temperatures[i])
Expand All @@ -107,6 +107,8 @@ def publish(temperatures, battery, heating_element, client, base_topic, device_n
client.publish("{0}/{1}/battery".format(base_topic, device_name), battery)
if heating_element:
client.publish("{0}/{1}/heating_element".format(base_topic, device_name), heating_element)
if propane_level:
client.publish("{0}/{1}/propane_level".format(base_topic, device_name), propane_level)


def get_devices(device_config):
Expand Down

0 comments on commit e6522bf

Please sign in to comment.