bluetooth_clocks.devices package#

Device-specific Bluetooth clock support.

Each submodule in this package implements support for a specific type of Bluetooth clock.

Each class in these submodules implements support for a specific model Bluetooth clock.

For instance, the bluetooth_clocks.devices.thermopro module has classes bluetooth_clocks.devices.thermopro.TP358 and bluetooth_clocks.devices.thermopro.TP393 for the ThermoPro TP358 and TP393, respectively.

Submodules#

bluetooth_clocks.devices.current_time_service module#

Bluetooth clock support for devices implementing the Current Time Service.

This includes the PineTime with InfiniTime firmware.

class bluetooth_clocks.devices.current_time_service.CurrentTimeService(device: BLEDevice)[source]#

Bases: BluetoothClock

Bluetooth clock support for devices implementing the Current Time Service.

This implements the standardized Bluetooth service Current Time Service (https://www.bluetooth.com/specifications/specs/current-time-service-1-1/).

CHAR_UUID: ClassVar[UUID] = UUID('00002a2b-0000-1000-8000-00805f9b34fb')#

The UUID of the characteristic used to read/write the time.

DEVICE_TYPE: ClassVar[str] = 'Current Time Service'#

The name of the device type.

SERVICE_UUID: ClassVar[UUID] = UUID('00001805-0000-1000-8000-00805f9b34fb')#

The UUID of the service used to read/write the time.

TIME_GET_FORMAT: ClassVar[str | None] = '<HBBBBBBB'#

The format string to convert bytes read from the Current Time Service to a time.

This starts with an unsigned short in little-endian format, followed by seven bytes.

TIME_SET_FORMAT: ClassVar[str] = '<HBBBBBBBB'#

The format string to convert a time to bytes written to the device.

This starts with an unsigned short in little-endian format, followed by eight bytes.

WRITE_WITH_RESPONSE: ClassVar[bool] = True#

Writing the time to the Current Time Service needs write with response.

get_bytes_from_time(timestamp: float, ampm: bool = False) bytes[source]#

Generate the bytes to set the time on the Current Time Service.

Parameters:
  • timestamp (float) – The time encoded as a Unix timestamp.

  • ampm (bool) – True if the device should show the time with AM/PM, False if it should use 24-hour format. The Current Time Service ignores this argument, as it doesn’t support this option.

Returns:

The bytes needed to set the time of the device to timestamp.

Return type:

bytes

get_time_from_bytes(time_bytes: bytes) float[source]#

Convert bytes read from the Current Time Service to a timestamp.

Parameters:

time_bytes (bytes) – The raw bytes read from the device.

Raises:

InvalidTimeBytesError – If time_bytes don’t have the right format.

Returns:

The time encoded as a Unix timestamp.

Return type:

float

classmethod recognize(device: BLEDevice, advertisement_data: AdvertisementData) bool[source]#

Recognize the Current Time Service from advertisement data.

This checks whether the Current Time Service’s service UUID is in the list of advertised service UUIDs.

Parameters:
  • device (BLEDevice) – The Bluetooth device.

  • advertisement_data (AdvertisementData) – The advertisement data.

Returns:

True if the device is recognized as a Current Time Service, False otherwise.

Return type:

bool

class bluetooth_clocks.devices.current_time_service.InfiniTime(device: BLEDevice)[source]#

Bases: CurrentTimeService

Bluetooth clock support for the PineTime with InfiniTime firmware.

DEVICE_TYPE: ClassVar[str] = 'InfiniTime'#

The name of the device type.

LOCAL_NAME: ClassVar[str | None] = 'InfiniTime'#

The local name used to recognize this type of device.

LOCAL_NAME_STARTS_WITH: ClassVar[bool | None] = False#

The local name should exactly match LOCAL_NAME.

classmethod recognize(device: BLEDevice, advertisement_data: AdvertisementData) bool[source]#

Recognize the PineTime with InfiniTime firmware from advertisement data.

This checks whether the advertisement data has a local name that is equal to or starts with LOCAL_NAME.

Parameters:
  • device (BLEDevice) – The Bluetooth device.

  • advertisement_data (AdvertisementData) – The advertisement data.

Returns:

True if the device is recognized as a PineTime with InfiniTime firmware, False otherwise.

Return type:

bool

bluetooth_clocks.devices.pvvx module#

Bluetooth clock support for devices running the PVVX firmware.

class bluetooth_clocks.devices.pvvx.PVVX(device: BLEDevice)[source]#

Bases: BluetoothClock

Bluetooth clock support for devices running the PVVX firmware.

CHAR_UUID: ClassVar[UUID] = UUID('00001f1f-0000-1000-8000-00805f9b34fb')#

The UUID of the characteristic used to read/write the time.

DEVICE_TYPE: ClassVar[str] = 'PVVX'#

The name of the device type.

PVVX_GET_SET_TIME_COMMAND = 35#

Command for PVVX firmware to Get/Set Time.

SERVICE_DATA_UUID = UUID('0000181a-0000-1000-8000-00805f9b34fb')#

UUID of the service data the PVVX device is advertising.

SERVICE_UUID: ClassVar[UUID] = UUID('00001f10-0000-1000-8000-00805f9b34fb')#

The UUID of the service used to read/write the time.

TIME_GET_FORMAT: ClassVar[str | None] = '<BLL'#

The format string to convert bytes read from the device to a time.

TIME_SET_FORMAT: ClassVar[str] = '<BL'#

The format string to convert a time to bytes written to the PVVX device.

WRITE_WITH_RESPONSE: ClassVar[bool] = False#

Writing the time to the PVVX device needs write without response.

get_bytes_from_time(timestamp: float, ampm: bool = False) bytes[source]#

Generate the bytes to set the time on the PVVX device.

Parameters:
  • timestamp (float) – The time encoded as a Unix timestamp.

  • ampm (bool) – True if the device should show the time with AM/PM, False if it should use 24-hour format. The PVVX device ignores this argument, as it doesn’t support this option.

Returns:

The bytes needed to set the time of the device to timestamp.

Return type:

bytes

async get_time() float[source]#

Get the time of the PVVX device.

Returns:

The time of the Bluetooth clock.

Return type:

float

get_time_from_bytes(time_bytes: bytes) float[source]#

Convert bytes read from the PVVX device to a timestamp.

Parameters:

time_bytes (bytes) – The raw bytes read from the device.

Raises:

InvalidTimeBytesError – If time_bytes don’t have the right format.

Returns:

The time encoded as a Unix timestamp.

Return type:

float

classmethod recognize(device: BLEDevice, advertisement_data: AdvertisementData) bool[source]#

Recognize the PVVX device from advertisement data.

This checks whether the advertisement has service data with service UUID 0x181a (PVVX custom format).

Parameters:
  • device (BLEDevice) – The Bluetooth device.

  • advertisement_data (AdvertisementData) – The advertisement data.

Returns:

True if the device is recognized as a PVVX device, False otherwise.

Return type:

bool

bluetooth_clocks.devices.qingping module#

Bluetooth clock support for Qingping clocks.

class bluetooth_clocks.devices.qingping.CGC1(device: BLEDevice)[source]#

Bases: BluetoothClock

Bluetooth clock support for the Qingping BT Clock Lite (CGC1).

CHAR_UUID: ClassVar[UUID] = UUID('00000001-0000-1000-8000-00805f9b34fb')#

The UUID of the characteristic used to write the time.

DEVICE_TYPE: ClassVar[str] = 'Qingping BT Clock Lite'#

The name of the device type.

LOCAL_NAME: ClassVar[str | None] = 'Qingping BT Clock Lite'#

The local name used to recognize this type of device.

LOCAL_NAME_STARTS_WITH: ClassVar[bool | None] = False#

The local name should exactly match LOCAL_NAME.

SERVICE_UUID: ClassVar[UUID] = UUID('22210000-554a-4546-5542-46534450464d')#

The UUID of the service used to write the time.

TIME_GET_FORMAT: ClassVar[str | None] = None#

The Qingping BT Clock Lite doesn’t support reading the time.

TIME_SET_FORMAT: ClassVar[str] = '<BBL'#

The format string to convert a time to bytes written to the device.

This starts with two bytes, followed by an unsigned long in little-endian format.

WRITE_WITH_RESPONSE: ClassVar[bool] = True#

We use write with response to write the time to the Qingping BT Clock Lite.

Note: The device also supports write without response.

get_bytes_from_time(timestamp: float, ampm: bool = False) bytes[source]#

Generate the bytes to set the time on the Qingping BT Clock Lite.

Parameters:
  • timestamp (float) – The time encoded as a Unix timestamp.

  • ampm (bool) – True if the device should show the time with AM/PM, False if it should use 24-hour format. The Qingping BT Clock Lite ignores this argument, as it doesn`t support this option.

Returns:

The bytes needed to set the time of the device to timestamp.

Return type:

bytes

bluetooth_clocks.devices.thermopro module#

Bluetooth clock support for ThermoPro sensors with clock.

class bluetooth_clocks.devices.thermopro.TP358(device: BLEDevice)[source]#

Bases: TPXXX

Bluetooth clock support for the ThermoPro TP358.

DEVICE_TYPE: ClassVar[str] = 'ThermoPro TP358'#

The name of the device type.

LOCAL_NAME: ClassVar[str | None] = 'TP358'#

The local name used to recognize this type of device.

LOCAL_NAME_STARTS_WITH: ClassVar[bool | None] = True#

The local name should start with LOCAL_NAME.

class bluetooth_clocks.devices.thermopro.TP393(device: BLEDevice)[source]#

Bases: TPXXX

Bluetooth clock support for the ThermoPro TP393.

DEVICE_TYPE: ClassVar[str] = 'ThermoPro TP393'#

The name of the device type.

LOCAL_NAME: ClassVar[str | None] = 'TP393'#

The local name used to recognize this type of device.

LOCAL_NAME_STARTS_WITH: ClassVar[bool | None] = True#

The local name should start with LOCAL_NAME.

class bluetooth_clocks.devices.thermopro.TPXXX(device: BLEDevice)[source]#

Bases: BluetoothClock

Bluetooth clock support for ThermoPro sensors with clock.

This class isn’t meant to be instantiated. Subclasses implement support for specific ThermoPro device types by giving values to the class variables DEVICE_TYPE, LOCAL_NAME, and LOCAL_NAME_STARTS_WITH.

CHAR_UUID: ClassVar[UUID] = UUID('00010203-0405-0607-0809-0a0b0c0d2b11')#

The UUID of the characteristic used to write the time.

SERVICE_UUID: ClassVar[UUID] = UUID('00010203-0405-0607-0809-0a0b0c0d1910')#

The UUID of the service used to write the time.

TIME_GET_FORMAT: ClassVar[str | None] = None#

ThermoPro devices don`t support reading the time.

TIME_SET_FORMAT: ClassVar[str] = 'BBBBBBBBBB'#

The format string to convert a time to bytes written to the device.

These are ten bytes.

WRITE_WITH_RESPONSE: ClassVar[bool] = False#

Writing the time to ThermoPro devices needs write without response.

get_bytes_from_time(timestamp: float, ampm: bool = False) bytes[source]#

Generate the bytes to set the time on ThermoPro devices.

Parameters:
  • timestamp (float) – The time encoded as a Unix timestamp.

  • ampm (bool) – True if the device should show the time with AM/PM, False if it should use 24-hour format.

Returns:

The bytes needed to set the time of the device to timestamp.

Return type:

bytes

bluetooth_clocks.devices.xiaomi module#

Bluetooth clock support for Xiaomi devices.

class bluetooth_clocks.devices.xiaomi.LYWSD02(device: BLEDevice)[source]#

Bases: BluetoothClock

Bluetooth clock support for the Xiaomi LYWSD02.

CHAR_UUID: ClassVar[UUID] = UUID('ebe0ccb7-7a0a-4b0c-8a1a-6ff2997da3a6')#

The UUID of the characteristic used to write the time.

DEVICE_TYPE: ClassVar[str] = 'Xiaomi LYWSD02'#

The name of the device type.

LOCAL_NAME: ClassVar[str | None] = 'LYWSD02'#

The local name used to recognize this type of device.

LOCAL_NAME_STARTS_WITH: ClassVar[bool | None] = False#

The local name should exactly match LOCAL_NAME.

SERVICE_UUID: ClassVar[UUID] = UUID('ebe0ccb0-7a0a-4b0c-8a1a-6ff2997da3a6')#

The UUID of the service used to write the time.

TIME_GET_FORMAT: ClassVar[str | None] = '<Lb'#

The format string to convert bytes read from the device to a time.

TIME_SET_FORMAT: ClassVar[str] = '<Lb'#

The format string to convert a time to bytes written to the device.

WRITE_WITH_RESPONSE: ClassVar[bool] = False#

Writing the time to the device needs write without response.

get_bytes_from_time(timestamp: float, ampm: bool = False) bytes[source]#

Generate the bytes to set the time on the Xiaomi LYWSD02.

Parameters:
  • timestamp (float) – The time encoded as a Unix timestamp.

  • ampm (bool) – True if the device should show the time with AM/PM, False if it should use 24-hour format. The Xiaomi LYWSD02 ignores this argument, as it doesn’t support this option.

Returns:

The bytes needed to set the time of the device to timestamp.

Return type:

bytes

get_time_from_bytes(time_bytes: bytes) float[source]#

Convert bytes read from the Xiaomi LYWSD02 to a timestamp.

Parameters:

time_bytes (bytes) – The raw bytes read from the device.

Raises:

InvalidTimeBytesError – If time_bytes don’t have the right format.

Returns:

The time encoded as a Unix timestamp.

Return type:

float