togrill-bluetooth 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- togrill_bluetooth/__init__.py +22 -0
- togrill_bluetooth/__main__.py +172 -0
- togrill_bluetooth/const.py +23 -0
- togrill_bluetooth/exceptions.py +2 -0
- togrill_bluetooth/parse.py +93 -0
- togrill_bluetooth/parse_packets.py +294 -0
- togrill_bluetooth/py.typed +0 -0
- togrill_bluetooth-0.1.1.dist-info/METADATA +72 -0
- togrill_bluetooth-0.1.1.dist-info/RECORD +12 -0
- togrill_bluetooth-0.1.1.dist-info/WHEEL +4 -0
- togrill_bluetooth-0.1.1.dist-info/entry_points.txt +2 -0
- togrill_bluetooth-0.1.1.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""ToGrill main module"""
|
|
2
|
+
|
|
3
|
+
from bleak.uuids import register_uuids
|
|
4
|
+
|
|
5
|
+
from .const import MainService
|
|
6
|
+
from .parse import Service
|
|
7
|
+
|
|
8
|
+
register_uuids(
|
|
9
|
+
{service.uuid: f"ToGrill {service.__name__}" for service in Service.registry.values()}
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
register_uuids(
|
|
13
|
+
{
|
|
14
|
+
char.uuid: f"ToGrill {service.__name__} {char.name}"
|
|
15
|
+
for service in Service.registry.values()
|
|
16
|
+
for char in service.characteristics()
|
|
17
|
+
}
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
__all__ = ( # noqa: F405
|
|
21
|
+
MainService
|
|
22
|
+
)
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
from datetime import timedelta
|
|
2
|
+
|
|
3
|
+
import anyio
|
|
4
|
+
import asyncclick as click
|
|
5
|
+
from bleak import (
|
|
6
|
+
AdvertisementData,
|
|
7
|
+
BleakClient,
|
|
8
|
+
BleakGATTCharacteristic,
|
|
9
|
+
BleakScanner,
|
|
10
|
+
BLEDevice,
|
|
11
|
+
)
|
|
12
|
+
from bleak.uuids import uuidstr_to_str
|
|
13
|
+
|
|
14
|
+
from .const import MainService, ManufacturerData
|
|
15
|
+
from .exceptions import DecodeError
|
|
16
|
+
from .parse import Characteristic, NotifyCharacteristic, WriteCharacteristic
|
|
17
|
+
from .parse_packets import (
|
|
18
|
+
PacketA0Notify,
|
|
19
|
+
PacketA1Notify,
|
|
20
|
+
PacketA7Write,
|
|
21
|
+
PacketA300Write,
|
|
22
|
+
PacketA301Write,
|
|
23
|
+
PacketNotify,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@click.group()
|
|
28
|
+
async def cli():
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@cli.command()
|
|
33
|
+
async def scan():
|
|
34
|
+
click.echo("Scanning for devices")
|
|
35
|
+
|
|
36
|
+
devices = set()
|
|
37
|
+
|
|
38
|
+
def detected(device: BLEDevice, advertisement: AdvertisementData):
|
|
39
|
+
if device not in devices:
|
|
40
|
+
if MainService.uuid not in advertisement.service_uuids:
|
|
41
|
+
return
|
|
42
|
+
devices.add(device)
|
|
43
|
+
|
|
44
|
+
click.echo(f"Device: {device}")
|
|
45
|
+
for service in advertisement.service_uuids:
|
|
46
|
+
click.echo(f" - Service: {service} {uuidstr_to_str(service)}")
|
|
47
|
+
click.echo(f" - Data: {advertisement.service_data}")
|
|
48
|
+
click.echo(f" - Manu: {advertisement.manufacturer_data}")
|
|
49
|
+
|
|
50
|
+
if data := advertisement.manufacturer_data.get(ManufacturerData.company):
|
|
51
|
+
decoded = ManufacturerData.decode(data)
|
|
52
|
+
click.echo(f" - : {decoded}")
|
|
53
|
+
|
|
54
|
+
click.echo(f" - RSSI: {advertisement.rssi}")
|
|
55
|
+
click.echo()
|
|
56
|
+
|
|
57
|
+
async with BleakScanner(detected, service_uuids=[MainService.uuid]):
|
|
58
|
+
await anyio.sleep_forever()
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@cli.group(chain=True)
|
|
62
|
+
@click.argument("address")
|
|
63
|
+
@click.option("--code", default="")
|
|
64
|
+
@click.pass_context
|
|
65
|
+
async def connect(ctx: click.Context, address: str, code: str):
|
|
66
|
+
click.echo(f"Connecting to: {address} ...", nl=False)
|
|
67
|
+
client = await ctx.with_async_resource(BleakClient(address, timeout=20))
|
|
68
|
+
ctx.obj = client
|
|
69
|
+
click.echo(" Done")
|
|
70
|
+
|
|
71
|
+
def notify_data(char_specifier: BleakGATTCharacteristic, data: bytearray):
|
|
72
|
+
try:
|
|
73
|
+
packet_data = NotifyCharacteristic.decode(data)
|
|
74
|
+
packet = PacketNotify.decode(packet_data)
|
|
75
|
+
click.echo(f"Notify: {packet}")
|
|
76
|
+
except DecodeError as exc:
|
|
77
|
+
click.echo(f"Failed to decode: {data.hex()} with error {exc}")
|
|
78
|
+
|
|
79
|
+
await client.start_notify(MainService.notify.uuid, notify_data)
|
|
80
|
+
|
|
81
|
+
await client.write_gatt_char(
|
|
82
|
+
MainService.write.uuid, WriteCharacteristic.encode(PacketA0Notify.request()), False
|
|
83
|
+
)
|
|
84
|
+
await client.write_gatt_char(
|
|
85
|
+
MainService.write.uuid, WriteCharacteristic.encode(PacketA1Notify.request()), False
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@connect.command()
|
|
90
|
+
@click.pass_obj
|
|
91
|
+
async def list(client: BleakClient):
|
|
92
|
+
for service in client.services:
|
|
93
|
+
click.echo(f"Service: {service}")
|
|
94
|
+
|
|
95
|
+
async def read_print(char: BleakGATTCharacteristic):
|
|
96
|
+
parser = Characteristic.registry.get(char.uuid)
|
|
97
|
+
if "read" in char.properties:
|
|
98
|
+
data = await client.read_gatt_char(char.uuid)
|
|
99
|
+
else:
|
|
100
|
+
data = None
|
|
101
|
+
click.echo(f" - {char}")
|
|
102
|
+
click.echo(f" - {char.properties}")
|
|
103
|
+
if data is not None and parser:
|
|
104
|
+
click.echo(f" - Data: {parser.decode(data)}")
|
|
105
|
+
|
|
106
|
+
async with anyio.create_task_group() as tg:
|
|
107
|
+
for char in service.characteristics:
|
|
108
|
+
tg.start_soon(read_print, char)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
@connect.command()
|
|
112
|
+
@click.argument("probe", type=int)
|
|
113
|
+
@click.argument("seconds", type=int)
|
|
114
|
+
@click.pass_obj
|
|
115
|
+
async def timer(client: BleakClient, probe: int, seconds: int):
|
|
116
|
+
click.echo(f"Setting timer on {probe} for delay {seconds} ...", nl=False)
|
|
117
|
+
await client.write_gatt_char(
|
|
118
|
+
MainService.write.uuid,
|
|
119
|
+
WriteCharacteristic.encode(
|
|
120
|
+
PacketA7Write(probe=probe, time=timedelta(seconds=seconds)).encode()
|
|
121
|
+
),
|
|
122
|
+
False,
|
|
123
|
+
)
|
|
124
|
+
click.echo(" Done")
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@connect.command()
|
|
128
|
+
@click.argument("probe", type=int)
|
|
129
|
+
@click.argument("minimum", type=float)
|
|
130
|
+
@click.argument("maximum", type=float)
|
|
131
|
+
@click.pass_obj
|
|
132
|
+
async def range(client: BleakClient, probe: int, minimum: float, maximum: float):
|
|
133
|
+
click.echo(f"Setting range cook on {probe} min: {minimum} max: {maximum} ...", nl=False)
|
|
134
|
+
await client.write_gatt_char(
|
|
135
|
+
MainService.write.uuid,
|
|
136
|
+
WriteCharacteristic.encode(
|
|
137
|
+
PacketA300Write(probe=probe, minimum=minimum, maximum=maximum).encode()
|
|
138
|
+
),
|
|
139
|
+
False,
|
|
140
|
+
)
|
|
141
|
+
click.echo(" Done")
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
@connect.command()
|
|
145
|
+
@click.argument("probe", type=int)
|
|
146
|
+
@click.argument("target", type=float)
|
|
147
|
+
@click.pass_obj
|
|
148
|
+
async def target(client: BleakClient, probe: int, target: float):
|
|
149
|
+
click.echo(f"Setting range cook on {probe} target: {target} ...", nl=False)
|
|
150
|
+
await client.write_gatt_char(
|
|
151
|
+
MainService.write.uuid,
|
|
152
|
+
WriteCharacteristic.encode(PacketA301Write(probe=probe, target=target).encode()),
|
|
153
|
+
False,
|
|
154
|
+
)
|
|
155
|
+
click.echo(" Done")
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
@connect.command()
|
|
159
|
+
async def wait():
|
|
160
|
+
click.echo("Waiting")
|
|
161
|
+
await anyio.sleep_forever()
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def main():
|
|
165
|
+
try:
|
|
166
|
+
cli()
|
|
167
|
+
except KeyboardInterrupt:
|
|
168
|
+
pass
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
if __name__ == "__main__":
|
|
172
|
+
main()
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Constants"""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import ClassVar
|
|
5
|
+
|
|
6
|
+
from togrill_bluetooth.parse import NotifyCharacteristic, WriteCharacteristic
|
|
7
|
+
|
|
8
|
+
from .parse import Service
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class MainService(Service):
|
|
12
|
+
uuid = "0000cee0-0000-1000-8000-00805f9b34fb"
|
|
13
|
+
write = WriteCharacteristic()
|
|
14
|
+
notify = NotifyCharacteristic()
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass
|
|
18
|
+
class ManufacturerData:
|
|
19
|
+
company: ClassVar[int] = 0x879A
|
|
20
|
+
|
|
21
|
+
@staticmethod
|
|
22
|
+
def decode(data: bytes):
|
|
23
|
+
return ManufacturerData()
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from functools import reduce
|
|
3
|
+
from itertools import chain, tee
|
|
4
|
+
from operator import xor
|
|
5
|
+
from typing import ClassVar, Generic, TypeVar
|
|
6
|
+
|
|
7
|
+
from .exceptions import DecodeError
|
|
8
|
+
|
|
9
|
+
CharacteristicType = TypeVar("CharacteristicType")
|
|
10
|
+
|
|
11
|
+
_PAYLOAD_PREFIX = [0x55, 0xAA]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def pretty_name(name: str):
|
|
15
|
+
data = name.split("_")
|
|
16
|
+
return " ".join(f"{part[0].upper()}{part[1:]}" for part in data)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass
|
|
20
|
+
class Characteristic(Generic[CharacteristicType]):
|
|
21
|
+
uuid: str
|
|
22
|
+
name: str = ""
|
|
23
|
+
registry: ClassVar[dict[str, "Characteristic"]] = {}
|
|
24
|
+
|
|
25
|
+
def __set_name__(self, _, name: str):
|
|
26
|
+
self.name = pretty_name(name)
|
|
27
|
+
|
|
28
|
+
def __post_init__(self):
|
|
29
|
+
self.registry[self.uuid] = self
|
|
30
|
+
|
|
31
|
+
@classmethod
|
|
32
|
+
def decode(cls, data: bytes) -> CharacteristicType:
|
|
33
|
+
raise NotImplementedError(f"Decoding of {type(cls)} is not implemented")
|
|
34
|
+
|
|
35
|
+
@classmethod
|
|
36
|
+
def encode(cls, data: CharacteristicType) -> bytes:
|
|
37
|
+
raise NotImplementedError(f"Encoding of {type(cls)} is not implemented")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class Service:
|
|
41
|
+
uuid: ClassVar[str]
|
|
42
|
+
registry: ClassVar[dict[str, "Service"]] = {}
|
|
43
|
+
|
|
44
|
+
def __init_subclass__(cls, /, **kwargs):
|
|
45
|
+
super().__init_subclass__(**kwargs)
|
|
46
|
+
cls.registry[cls.uuid] = cls
|
|
47
|
+
|
|
48
|
+
@classmethod
|
|
49
|
+
def characteristics(cls):
|
|
50
|
+
for value in vars(cls).values():
|
|
51
|
+
if isinstance(value, Characteristic):
|
|
52
|
+
yield value
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@dataclass
|
|
56
|
+
class NotifyCharacteristic(Characteristic[bytes]):
|
|
57
|
+
uuid: ClassVar[str] = "0000cee2-0000-1000-8000-00805f9b34fb"
|
|
58
|
+
|
|
59
|
+
@staticmethod
|
|
60
|
+
def decode(data: bytes) -> bytes:
|
|
61
|
+
if len(data) < 5:
|
|
62
|
+
raise DecodeError("Too short payload")
|
|
63
|
+
|
|
64
|
+
if data[0:2] != bytes(_PAYLOAD_PREFIX):
|
|
65
|
+
raise DecodeError("Missing header")
|
|
66
|
+
|
|
67
|
+
payload_len = int.from_bytes(data[2:4], "big")
|
|
68
|
+
|
|
69
|
+
if len(data) - 5 != payload_len:
|
|
70
|
+
raise DecodeError("Payload size mismatch")
|
|
71
|
+
|
|
72
|
+
payload = data[4 : 4 + payload_len]
|
|
73
|
+
checksum = data[4 + payload_len]
|
|
74
|
+
checksum_expected = reduce(xor, data[:-1])
|
|
75
|
+
if checksum_expected != checksum:
|
|
76
|
+
raise DecodeError(f"Expected checksum {checksum_expected:x} found {checksum:x}")
|
|
77
|
+
return payload
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@dataclass
|
|
81
|
+
class WriteCharacteristic(Characteristic[bytes]):
|
|
82
|
+
uuid: ClassVar[str] = "0000cee1-0000-1000-8000-00805f9b34fb"
|
|
83
|
+
|
|
84
|
+
@staticmethod
|
|
85
|
+
def encode(data: bytes) -> bytes:
|
|
86
|
+
payload = chain(_PAYLOAD_PREFIX, len(data).to_bytes(2, "big"), data)
|
|
87
|
+
payload, payload_copy = tee(payload, 2)
|
|
88
|
+
checksum = reduce(xor, payload_copy)
|
|
89
|
+
return bytes(chain(payload, [checksum]))
|
|
90
|
+
|
|
91
|
+
@staticmethod
|
|
92
|
+
def encode_set_backlight_always_on(value: bool) -> bytes:
|
|
93
|
+
return WriteCharacteristic.encode(bytes([0xAE, 0x05, 0x01 if value else 0x00]))
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from datetime import timedelta
|
|
3
|
+
from enum import IntEnum
|
|
4
|
+
from typing import ClassVar, Self
|
|
5
|
+
|
|
6
|
+
from .exceptions import DecodeError
|
|
7
|
+
|
|
8
|
+
_PACKET_REGISTRY: dict[int, "Packet"] = {}
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass
|
|
12
|
+
class Packet:
|
|
13
|
+
type: int
|
|
14
|
+
|
|
15
|
+
@classmethod
|
|
16
|
+
def decode(cls, data: bytes) -> Self:
|
|
17
|
+
raise NotImplementedError()
|
|
18
|
+
|
|
19
|
+
def encode(self) -> bytes:
|
|
20
|
+
raise NotImplementedError()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass
|
|
24
|
+
class PacketNotify(Packet):
|
|
25
|
+
def __init_subclass__(cls, /, **kwargs):
|
|
26
|
+
super().__init_subclass__(**kwargs)
|
|
27
|
+
if hasattr(cls, "type"):
|
|
28
|
+
_PACKET_REGISTRY[cls.type] = cls
|
|
29
|
+
|
|
30
|
+
@classmethod
|
|
31
|
+
def decode(cls, data: bytes) -> Self:
|
|
32
|
+
if len(data) < 1:
|
|
33
|
+
raise DecodeError("Failed to parse packet")
|
|
34
|
+
cls = _PACKET_REGISTRY.get(data[0])
|
|
35
|
+
if cls:
|
|
36
|
+
return cls.decode(data)
|
|
37
|
+
return PacketUnknown(data[0], data[1:])
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@dataclass
|
|
41
|
+
class PacketA0Notify(PacketNotify):
|
|
42
|
+
"""Device status"""
|
|
43
|
+
|
|
44
|
+
type: ClassVar[int] = 0xA0
|
|
45
|
+
battery: int
|
|
46
|
+
version_major: int
|
|
47
|
+
version_minor: int
|
|
48
|
+
function_type: int
|
|
49
|
+
probe_number: int
|
|
50
|
+
ambient: bool
|
|
51
|
+
alarm_interval: int
|
|
52
|
+
alarm_sound: bool
|
|
53
|
+
|
|
54
|
+
@classmethod
|
|
55
|
+
def decode(cls, data: bytes) -> Self:
|
|
56
|
+
if len(data) < 6:
|
|
57
|
+
raise DecodeError("Packet too short")
|
|
58
|
+
if data[0] != cls.type:
|
|
59
|
+
raise DecodeError("Failed to parse packet")
|
|
60
|
+
|
|
61
|
+
battery = data[1]
|
|
62
|
+
version_major = data[2]
|
|
63
|
+
version_minor = data[3]
|
|
64
|
+
_unknown = data[4]
|
|
65
|
+
bitfield = data[5]
|
|
66
|
+
function_type = bitfield & 0xF
|
|
67
|
+
probe_number = (bitfield >> 4) & 0x7
|
|
68
|
+
ambient = bool(bitfield >> 7)
|
|
69
|
+
|
|
70
|
+
alarm_interval = 5
|
|
71
|
+
alarm_sound = True
|
|
72
|
+
if len(data) > 6:
|
|
73
|
+
alarm_interval = data[6]
|
|
74
|
+
alarm_sound = data[7] == 1
|
|
75
|
+
|
|
76
|
+
return PacketA0Notify(
|
|
77
|
+
battery=battery,
|
|
78
|
+
version_major=version_major,
|
|
79
|
+
version_minor=version_minor,
|
|
80
|
+
function_type=function_type,
|
|
81
|
+
probe_number=probe_number,
|
|
82
|
+
ambient=ambient,
|
|
83
|
+
alarm_interval=alarm_interval,
|
|
84
|
+
alarm_sound=alarm_sound,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
@classmethod
|
|
88
|
+
def request(cls) -> None:
|
|
89
|
+
return bytes(
|
|
90
|
+
[
|
|
91
|
+
cls.type,
|
|
92
|
+
0x00,
|
|
93
|
+
0x00,
|
|
94
|
+
]
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
@dataclass
|
|
99
|
+
class PacketA1Notify(PacketNotify):
|
|
100
|
+
"""Temperature on probes"""
|
|
101
|
+
|
|
102
|
+
type: ClassVar[int] = 0xA1
|
|
103
|
+
temperatures: list[float | None]
|
|
104
|
+
|
|
105
|
+
@classmethod
|
|
106
|
+
def decode(cls, data: bytes) -> Self:
|
|
107
|
+
if len(data) < 1:
|
|
108
|
+
raise DecodeError("Packet too short")
|
|
109
|
+
if data[0] != cls.type:
|
|
110
|
+
raise DecodeError("Failed to parse packet")
|
|
111
|
+
|
|
112
|
+
temperatures = [
|
|
113
|
+
int.from_bytes(data[index : index + 2], "big") for index in range(1, len(data), 2)
|
|
114
|
+
]
|
|
115
|
+
|
|
116
|
+
def convert(value: int) -> float | None:
|
|
117
|
+
if value == 65535:
|
|
118
|
+
return None
|
|
119
|
+
if value > 32768:
|
|
120
|
+
return (value - 32768) / 10
|
|
121
|
+
return value / 10
|
|
122
|
+
|
|
123
|
+
temperatures = [convert(temperature) for temperature in temperatures]
|
|
124
|
+
|
|
125
|
+
return PacketA1Notify(temperatures=temperatures)
|
|
126
|
+
|
|
127
|
+
@classmethod
|
|
128
|
+
def request(cls) -> None:
|
|
129
|
+
return bytes(
|
|
130
|
+
[
|
|
131
|
+
cls.type,
|
|
132
|
+
0x00,
|
|
133
|
+
]
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
@dataclass
|
|
138
|
+
class PacketA300Write(Packet):
|
|
139
|
+
"""Set min max temperature."""
|
|
140
|
+
|
|
141
|
+
type: ClassVar[int] = 0xA3
|
|
142
|
+
probe: int
|
|
143
|
+
subtype: ClassVar[int] = 0x00
|
|
144
|
+
minimum: float
|
|
145
|
+
maximum: float
|
|
146
|
+
|
|
147
|
+
@classmethod
|
|
148
|
+
def decode(cls, data: bytes) -> Self:
|
|
149
|
+
if len(data) < 7:
|
|
150
|
+
raise DecodeError("Packet too short")
|
|
151
|
+
if data[2] != cls.subtype:
|
|
152
|
+
raise DecodeError("Invalid subtype")
|
|
153
|
+
return cls(
|
|
154
|
+
probe=data[1],
|
|
155
|
+
minimum=int.from_bytes(data[3:5], "big") / 10,
|
|
156
|
+
maximum=int.from_bytes(data[5:7], "big") / 10,
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
def encode(self) -> bytes:
|
|
160
|
+
min_temp = round(self.minimum * 10).to_bytes(2, "big")
|
|
161
|
+
max_temp = round(self.maximum * 10).to_bytes(2, "big")
|
|
162
|
+
return bytes([self.type, self.probe, self.subtype, *min_temp, *max_temp])
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
@dataclass
|
|
166
|
+
class PacketA301Write(Packet):
|
|
167
|
+
"""Set target temperature."""
|
|
168
|
+
|
|
169
|
+
type: ClassVar[int] = 0xA3
|
|
170
|
+
probe: int
|
|
171
|
+
subtype: ClassVar[int] = 0x01
|
|
172
|
+
target: float
|
|
173
|
+
|
|
174
|
+
@classmethod
|
|
175
|
+
def decode(cls, data: bytes) -> Self:
|
|
176
|
+
if len(data) < 7:
|
|
177
|
+
raise DecodeError("Packet too short")
|
|
178
|
+
if data[2] != cls.subtype:
|
|
179
|
+
raise DecodeError("Invalid subtype")
|
|
180
|
+
return cls(
|
|
181
|
+
probe=data[1],
|
|
182
|
+
target=int.from_bytes(data[3:5], "big") / 10,
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
def encode(self) -> bytes:
|
|
186
|
+
target_temp = round(self.target * 10).to_bytes(2, "big")
|
|
187
|
+
return bytes([self.type, self.probe, self.subtype, *target_temp, 0, 0])
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
@dataclass
|
|
191
|
+
class PacketA303Write(Packet):
|
|
192
|
+
"""Set target temperature."""
|
|
193
|
+
|
|
194
|
+
type: ClassVar[int] = 0xA3
|
|
195
|
+
probe: int
|
|
196
|
+
subtype: ClassVar[int] = 0x03
|
|
197
|
+
grill_type: int
|
|
198
|
+
|
|
199
|
+
@classmethod
|
|
200
|
+
def decode(cls, data: bytes) -> Self:
|
|
201
|
+
if len(data) < 7:
|
|
202
|
+
raise DecodeError("Packet too short")
|
|
203
|
+
if data[2] != cls.subtype:
|
|
204
|
+
raise DecodeError("Invalid subtype")
|
|
205
|
+
return cls(
|
|
206
|
+
probe=data[1],
|
|
207
|
+
grill_type=data[4],
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
def encode(self) -> bytes:
|
|
211
|
+
return bytes([self.type, self.probe, self.subtype, 0, self.grill_type, 0, 0])
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
@dataclass
|
|
215
|
+
class PacketA5Notify(PacketNotify):
|
|
216
|
+
"""Status from probe"""
|
|
217
|
+
|
|
218
|
+
type: ClassVar[int] = 0xA5
|
|
219
|
+
probe: int
|
|
220
|
+
message: int
|
|
221
|
+
|
|
222
|
+
class Message(IntEnum):
|
|
223
|
+
PROBE_ACKNOWLEDGE = 0
|
|
224
|
+
PROBE_ALARM = 5
|
|
225
|
+
PROBE_DISCONNECTED = 6
|
|
226
|
+
|
|
227
|
+
@classmethod
|
|
228
|
+
def decode(cls, data: bytes) -> Self:
|
|
229
|
+
if len(data) < 3:
|
|
230
|
+
raise DecodeError("Packet too short")
|
|
231
|
+
if data[0] != cls.type:
|
|
232
|
+
raise DecodeError("Failed to parse packet")
|
|
233
|
+
|
|
234
|
+
try:
|
|
235
|
+
message = PacketA5Notify.Message(data[2])
|
|
236
|
+
except ValueError:
|
|
237
|
+
message = data[2]
|
|
238
|
+
|
|
239
|
+
return PacketA5Notify(probe=data[1], message=message)
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
@dataclass
|
|
243
|
+
class PacketA7Notify(PacketNotify):
|
|
244
|
+
"""Set timer."""
|
|
245
|
+
|
|
246
|
+
type: ClassVar[int] = 0xA7
|
|
247
|
+
data: int
|
|
248
|
+
|
|
249
|
+
@classmethod
|
|
250
|
+
def decode(cls, data: bytes) -> Self:
|
|
251
|
+
if len(data) < 2:
|
|
252
|
+
raise DecodeError("Packet too short")
|
|
253
|
+
return PacketA7Notify(data=data[1])
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
@dataclass
|
|
257
|
+
class PacketA7Write(Packet):
|
|
258
|
+
"""Set timer."""
|
|
259
|
+
|
|
260
|
+
type: ClassVar[int] = 0xA7
|
|
261
|
+
probe: int
|
|
262
|
+
time: timedelta
|
|
263
|
+
unknown: int = 1
|
|
264
|
+
|
|
265
|
+
@classmethod
|
|
266
|
+
def decode(cls, data: bytes) -> Self:
|
|
267
|
+
if len(data) < 5:
|
|
268
|
+
raise DecodeError("Packet too short")
|
|
269
|
+
return PacketA7Write(
|
|
270
|
+
time=timedelta(seconds=int.from_bytes(data[3:5], "big")), probe=data[1], unknown=data[2]
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
def encode(self) -> bytes:
|
|
274
|
+
seconds = round(self.time.total_seconds())
|
|
275
|
+
return bytes(
|
|
276
|
+
[
|
|
277
|
+
self.type,
|
|
278
|
+
self.probe,
|
|
279
|
+
self.unknown,
|
|
280
|
+
*seconds.to_bytes(2, "big"),
|
|
281
|
+
]
|
|
282
|
+
)
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
@dataclass
|
|
286
|
+
class PacketUnknown(Packet):
|
|
287
|
+
type: int
|
|
288
|
+
data: bytes
|
|
289
|
+
|
|
290
|
+
@classmethod
|
|
291
|
+
def decode(cls, data: bytes) -> Self:
|
|
292
|
+
if len(data) < 1:
|
|
293
|
+
raise DecodeError("Packet too short")
|
|
294
|
+
return PacketUnknown(data[0], data=data[1:])
|
|
File without changes
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: togrill-bluetooth
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Module to handle communication with ToGrill compatible temperature probes.
|
|
5
|
+
Project-URL: Repository, https://github.com/elupus/togrill-bluetooth
|
|
6
|
+
Author-email: Joakim Plate <elupus@ecce.se>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
Requires-Python: <4.0,>=3.11
|
|
19
|
+
Requires-Dist: bleak>=1.0.1
|
|
20
|
+
Provides-Extra: cli
|
|
21
|
+
Requires-Dist: anyio>=4.9.0; extra == 'cli'
|
|
22
|
+
Requires-Dist: asyncclick>=8.1.8; extra == 'cli'
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# ToGrill Bluetooth Library
|
|
26
|
+
|
|
27
|
+
ToGrill is a Python library for communicating with ToGrill Bluetooth-enabled devices, such as smart grilling thermometers. It provides tools for scanning, connecting, and interacting with these devices, including reading probe temperatures, setting timers, and configuring temperature ranges.
|
|
28
|
+
|
|
29
|
+
It's main target use is for integration into Home Assistant integrations.
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
- Scan for ToGrill Bluetooth devices
|
|
34
|
+
- Connect and interact with devices using BLE
|
|
35
|
+
- Read probe temperatures and device status
|
|
36
|
+
- Set timers and temperature ranges
|
|
37
|
+
- Command-line interface for easy usage and scripting
|
|
38
|
+
|
|
39
|
+
## Command-Line Interface
|
|
40
|
+
|
|
41
|
+
### Commands
|
|
42
|
+
|
|
43
|
+
- scan
|
|
44
|
+
Scan for nearby ToGrill Bluetooth devices and display their information.
|
|
45
|
+
|
|
46
|
+
- connect `address`
|
|
47
|
+
Connect to a device by Bluetooth address. This command opens a group of subcommands:
|
|
48
|
+
Commands can be chained to perform multiple actions in one connection.
|
|
49
|
+
|
|
50
|
+
- list
|
|
51
|
+
List all GATT services and characteristics, and read available data.
|
|
52
|
+
|
|
53
|
+
- timer `probe` `seconds`
|
|
54
|
+
Set a timer on the specified probe for a given number of seconds.
|
|
55
|
+
|
|
56
|
+
- range `probe` `minimum` `maximum`
|
|
57
|
+
Set a minimum and maximum temperature range for a probe.
|
|
58
|
+
|
|
59
|
+
- target `probe` `target`
|
|
60
|
+
Set a target temperature for a probe.
|
|
61
|
+
|
|
62
|
+
- wait
|
|
63
|
+
Wait indefinitely, keeping the connection open.
|
|
64
|
+
|
|
65
|
+
### Examples
|
|
66
|
+
|
|
67
|
+
- `togrill-bluetooth scan`
|
|
68
|
+
- `togrill-bluetooth connect AA:BB:CC:DD:EE:FF list wait`
|
|
69
|
+
- `togrill-bluetooth connect AA:BB:CC:DD:EE:FF timer 1 600`
|
|
70
|
+
- `togrill-bluetooth connect AA:BB:CC:DD:EE:FF range 1 50.0 80.0`
|
|
71
|
+
- `togrill-bluetooth connect AA:BB:CC:DD:EE:FF target 1 65.0`
|
|
72
|
+
- `togrill-bluetooth connect AA:BB:CC:DD:EE:FF wait`
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
togrill_bluetooth/__init__.py,sha256=jaTs3I0fE6km0GM8uDkoP8Ll80Sc0IQ9Mqqva1_w4oI,467
|
|
2
|
+
togrill_bluetooth/__main__.py,sha256=-bQfF7TrFSq3ZRmhpfqcMG-4BWOk9YJd80l163OGXNA,5122
|
|
3
|
+
togrill_bluetooth/const.py,sha256=9XaXEp_Khf5j8vACz_FroVKSiBkjlfQVo_LuJKu1-Ic,491
|
|
4
|
+
togrill_bluetooth/exceptions.py,sha256=basP42yV4z44BNs-9iGK8wwPnwsznaSTIdOnqcB7yOw,39
|
|
5
|
+
togrill_bluetooth/parse.py,sha256=C8jizrTsqkxbeyf9egWLYxVo2DcQ_SpIT47jtE4B-h8,2795
|
|
6
|
+
togrill_bluetooth/parse_packets.py,sha256=qp1V6k5Suw8MvuKNKRSSob_Zfe1Lc4D8aO7jdQG8AiA,7413
|
|
7
|
+
togrill_bluetooth/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
togrill_bluetooth-0.1.1.dist-info/METADATA,sha256=d1aJoWOcWYzeIWUQyaLjxjv3sz1WYaLC4n4qe4fvB10,2610
|
|
9
|
+
togrill_bluetooth-0.1.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
10
|
+
togrill_bluetooth-0.1.1.dist-info/entry_points.txt,sha256=ZLNWmt_3nm-pK44ehAGPwpOVewp6y_MrDAW6c_pEegI,70
|
|
11
|
+
togrill_bluetooth-0.1.1.dist-info/licenses/LICENSE,sha256=9Wz5CJxMbCI09TnZiNHysXcda5NmdWD-qnKit1kQNyI,1069
|
|
12
|
+
togrill_bluetooth-0.1.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Joakim Plate
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|