Python的HomeKit配件协议(HAP)封装器
项目描述
此封装器封装了非常有用的 HAP-python 软件包,以便创建新的配件变得非常简单,特别是那些具有多个服务的配件。
以下是一个示例
class Temperature(gleeful.Accessory): temperature = gleeful.services.temperature.DS18B20(sensor_id='28-00000000000') class AccessoryInformation: Name = 'Temperature' Manufacturer = 'Matthew Schinckel' Model = 'DS18B20' SerialNumber = '28-00000000000' Temperature(persist_file='/path/to/temperature.state').start()
定义服务
服务必须从 gleeful.Service 继承,以便正确注册到配件中,并正确确定服务属性
class PIR(gleeful.Service): service = 'MotionSensor' def __init__(self, *args, **kwargs): from gpio import MotionSensor self.motion = self.service.get_characteristic('MotionDetected') self.detector = gpiozero.MotionSensor(kwargs.pop('gpio_pin')) super().__init__(*args, **kwargs) def run(self, sentinel): self.detector.when_motion = lambda: self.motion.set_value(True) self.detector.when_no_motion = lambda: self.motion.set_value(False)
您会注意到这个示例中有几个非常重要的事项
您在类中将服务定义为字符串:当使用类时,服务属性将不会是字符串,而是一个与HAP服务匹配的实例。
run方法接受一个额外的参数:可以用来触发重复代码或停止状态的哨兵。这在配件内的所有服务之间是共享的。
为什么使用这个而不是 HAP-python?
Gleeful使在单个配件内拥有多个服务变得容易,并在服务内封装逻辑。
它还允许您通过使用 .start() 直接从配件提供服务,尽管您也可以将配件传递给驱动器。
项目详情
关闭
gleeful-0.1.3.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | ad21af2045e258a36baa164824d839d27c03f3e7c5d9d85bb2cf364c24690908 |
|
MD5 | 390fe3747831619d4d1f4325e4a41c13 |
|
BLAKE2b-256 | 9b6bbbe67b77dd0efe956774b6765a55ed3dbbb73f65c4e79bf5bb15249d4763 |