utils.py
utils
¶
Helpful utils for processing mug data.
Attributes¶
Functions:¶
bytes_to_big_int
¶
bytes_to_big_int(
data: bytearray | bytes, signed: bool = False
) -> int
Convert bytes to big int.
Source code in ember_mug/utils.py
46 47 48 | |
bytes_to_little_int
¶
bytes_to_little_int(data: bytearray | bytes) -> int
Convert bytes to little int.
Source code in ember_mug/utils.py
41 42 43 | |
convert_temp_to_celsius
¶
convert_temp_to_celsius(temp: float) -> float
Convert to Celsius.
Source code in ember_mug/utils.py
56 57 58 | |
convert_temp_to_fahrenheit
¶
convert_temp_to_fahrenheit(temp: float) -> float
Convert to fahrenheit.
Source code in ember_mug/utils.py
51 52 53 | |
decode_byte_string
¶
decode_byte_string(data: bytes | bytearray) -> str
Convert bytes to text as Ember expects.
Source code in ember_mug/utils.py
25 26 27 28 29 30 31 32 33 | |
decode_date_time
¶
decode_date_time(
data: bytes | bytearray,
) -> datetime.datetime
Extract date time with timezone from bytes.
Source code in ember_mug/utils.py
79 80 81 82 83 84 85 86 87 | |
discover_services
async
¶
discover_services(
client: bleak.BleakClient,
) -> dict[str, typing.Any]
Log all services and all values for debugging/development.
Source code in ember_mug/utils.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
encode_byte_string
¶
encode_byte_string(data: str) -> bytes
Encode string from Ember Mug.
Source code in ember_mug/utils.py
36 37 38 | |
encode_date_time
¶
encode_date_time(date_time: datetime.datetime) -> bytes
Encode datetime with timezone as the mug expects.
Source code in ember_mug/utils.py
66 67 68 69 70 71 72 73 74 75 76 | |
get_colour_from_int
¶
get_colour_from_int(
colour_id: int,
) -> ember_mug.consts.DeviceColour | None
Extrapolate device colour from integer in advertiser data.
Source code in ember_mug/utils.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
get_model_from_id_and_gen
¶
get_model_from_id_and_gen(
model_id: int, generation: int
) -> ember_mug.consts.DeviceModel | None
Extract model from identifier in advertiser data.
Source code in ember_mug/utils.py
133 134 135 136 137 138 139 140 141 142 143 144 145 | |
get_model_from_single_int_and_services
¶
get_model_from_single_int_and_services(
model_id: int, service_uuids: list[str]
) -> ember_mug.consts.DeviceModel | None
Extrapolate device model from integer in advertiser data.
Source code in ember_mug/utils.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
get_model_info_from_advertiser_data
¶
get_model_info_from_advertiser_data(
advertisement: bleak.backends.scanner.AdvertisementData,
) -> ember_mug.data.ModelInfo
Extract model info from manufacturer data in advertiser data.
Source code in ember_mug/utils.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
guess_model_from_name
¶
guess_model_from_name(
name: str | None,
) -> ember_mug.consts.DeviceModel | None
Guess model from BLE name.
Source code in ember_mug/utils.py
148 149 150 151 152 153 154 155 156 | |
temp_from_bytes
¶
temp_from_bytes(temp_bytes: bytearray) -> float
Get temperature from bytearray.
Source code in ember_mug/utils.py
61 62 63 | |