def _set_services(self): """Add the AirQualitySensor services (one for PM2.5 and one for PM10). Also adds and configures optional characteristics, such as Name, AirParticulateSize, AirParticulateDensity. """ super(SDS011, self)._set_services() char_loader = loader.get_char_loader() # PM2.5 air_quality_pm25 = loader.get_serv_loader().get("AirQualitySensor") pm25_size = char_loader.get("AirParticulateSize") pm25_size.set_value(0, should_notify=False) self.pm25_density = char_loader.get("AirParticulateDensity") pm25_name = char_loader.get("Name") pm25_name.set_value("PM2.5", should_notify=False) self.pm25_quality = air_quality_pm25.get_characteristic("AirQuality") air_quality_pm25.add_characteristic(pm25_name, pm25_size, self.pm25_density) # PM10 air_quality_pm10 = loader.get_serv_loader().get("AirQualitySensor") pm10_size = char_loader.get("AirParticulateSize") pm10_size.set_value(1, should_notify=False) self.pm10_density = char_loader.get("AirParticulateDensity") pm10_name = char_loader.get("Name") pm10_name.set_value("PM10", should_notify=False) self.pm10_quality = air_quality_pm10.get_characteristic("AirQuality") air_quality_pm10.add_characteristic(pm10_name, pm10_size, self.pm10_density) self.add_service(air_quality_pm25) self.add_service(air_quality_pm10)
def add_preload_service(acc, service, chars=None, opt_chars=None): """Define and return a service to be available for the accessory.""" from pyhap.loader import get_serv_loader, get_char_loader service = get_serv_loader().get(service) if chars: chars = chars if isinstance(chars, list) else [chars] for char_name in chars: char = get_char_loader().get(char_name) service.add_characteristic(char) if opt_chars: opt_chars = opt_chars if isinstance(opt_chars, list) else [opt_chars] for opt_char_name in opt_chars: opt_char = get_char_loader().get(opt_char_name) service.add_opt_characteristic(opt_char) acc.add_service(service) return service
def _set_services(self): """Add the fan service. Also add optional characteristics to it.""" super(FakeFan, self)._set_services() service_loader = loader.get_serv_loader() fan_service = service_loader.get("Fan") # NOTE: Don't forget that all characteristics must be added to the service before # adding the service to the accessory, so that it can assign IIDs to all. # Add the optional RotationSpeed characteristic to the Fan rotation_speed_char = loader.get_char_loader().get("RotationSpeed") fan_service.add_opt_characteristic(rotation_speed_char) rotation_speed_char.setter_callback = self.set_rotation_speed # Add the optional RotationSpeed characteristic to the Fan rotation_dir_char = loader.get_char_loader().get("RotationDirection") fan_service.add_opt_characteristic(rotation_dir_char) rotation_dir_char.setter_callback = self.set_rotation_direction self.add_service(fan_service)
def add_preload_service(acc, service, chars=None): """Define and return a service to be available for the accessory.""" from pyhap.loader import get_serv_loader, get_char_loader service = get_serv_loader().get(service) if chars: chars = chars if isinstance(chars, list) else [chars] for char_name in chars: char = get_char_loader().get(char_name) service.add_characteristic(char) acc.add_service(service) return service
def _set_services(self): """Add the fan service. Also add optional characteristics to it.""" super(LightBulbDimmer, self)._set_services() service_loader = loader.get_serv_loader() fan_service = service_loader.get("Lightbulb") # NOTE: Don't forget that all characteristics must be added to the service before # adding the service to the accessory, so that it can assign IIDs to # all. # Add the optional RotationSpeed characteristic to the Fan # if (self.dimmer): rotation_speed_char = loader.get_char_loader().get("Brightness") fan_service.add_opt_characteristic(rotation_speed_char) rotation_speed_char.setter_callback = self.set_dimm # Add the optional RotationSpeed characteristic to the Fan # rotation_dir_char = loader.get_char_loader().get("RotationDirection") # fan_service.add_opt_characteristic(rotation_dir_char) # rotation_dir_char.setter_callback = self.set_rotation_direction self.add_service(fan_service) fan_service.get_characteristic("On").setter_callback = self.set_bulb
def _set_services(self): """ Add services to be supported (called from __init__). A loader creates Service and Characteristic objects based on json representation such as the Apple-defined ones in pyhap/resources/. """ # This call sets AccessoryInformation, so we'll do this below # super(CO2Accessory, self)._set_services() char_loader = loader.get_char_loader() serv_loader = loader.get_serv_loader() # Mandatory: Information about device info = self.monitor.info serv_info = serv_loader.get("AccessoryInformation") serv_info.get_characteristic("Name").set_value(NAME, False) serv_info.get_characteristic("Manufacturer").set_value(info['manufacturer'], False) serv_info.get_characteristic("Model").set_value(info['product_name'], False) serv_info.get_characteristic("SerialNumber").set_value(info['serial_no'], False) serv_info.get_characteristic("Identify").set_value(IDENTIFY, False) # Need to ensure AccessoryInformation is with IID 1 self.add_service(serv_info) # Temperature sensor: only mandatory characteristic serv_temp = serv_loader.get("TemperatureSensor") self.char_temp = serv_temp.get_characteristic("CurrentTemperature") serv_temp.add_characteristic(self.char_temp) # CO2 sensor: both mandatory and optional characteristic serv_co2 = serv_loader.get("CarbonDioxideSensor") self.char_high_co2 = serv_co2.get_characteristic("CarbonDioxideDetected") self.char_co2 = char_loader.get("CarbonDioxideLevel") serv_co2.add_characteristic(self.char_high_co2) serv_co2.add_opt_characteristic(self.char_co2) self.char_temp.setter_callback = self.temperature_changed self.char_co2.setter_callback = self.co2_changed self.add_service(serv_temp) self.add_service(serv_co2)