Example #1
0
    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)
Example #2
0
    def add_accessory(self, acc):
        """Adds an accessory to this bridge.

      Bridge accessories cannot be bridged. All accessories in this bridge must have
      unique AIDs and none of them must have the STANDALONE_AID.

      @param acc: The Accessory to be bridged.
      @type acc: Accessory
      """
        if acc.category == Category.BRIDGE:
            raise ValueError("Bridges cannot be bridged")

        if acc.aid and (acc.aid == self.aid or acc.aid in self.accessories):
            raise ValueError(
                "Duplicate AID found when attempting to add accessory")

        acc_uuid = uuid.uuid4()

        # The bridge has AID 1, start from 2 onwards
        acc.aid = len(self.accessories) + 2

        bridge_state_serv = get_serv_loader().get("BridgingState")
        bridge_state_serv.get_characteristic("AccessoryIdentifier")\
                         .set_value(acc_uuid, False)
        bridge_state_serv.get_characteristic("Reachable")\
                         .set_value(acc.reachable, False)
        bridge_state_serv.get_characteristic("Category")\
                         .set_value(acc.category, False)

        self.accessories[acc.aid] = acc
Example #3
0
    def _set_services(self):
        super()._set_services()

        outlet_service = loader.get_serv_loader().get('Outlet')
        self.add_service(outlet_service)
        self.on_char = outlet_service.get_characteristic('On')
        self.on_char.setter_callback = self.hk_callback
Example #4
0
    def _set_services(self):
        super(GarageDoor, self)._set_services()

        garage_door_opener_service = loader.get_serv_loader().get("GarageDoorOpener")
        self.add_service(garage_door_opener_service)
        garage_door_opener_service.get_characteristic(
            "TargetDoorState").setter_callback = self._pulse_door
    def _set_services(self):
        super(NodeMCU, self)._set_services()

        bulb_service = loader.get_serv_loader().get("Switch")
        self.add_service(bulb_service)

        self.switchState = bulb_service.get_characteristic("On")
        self.switchState.setter_callback = self.set_bulb
Example #6
0
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
Example #7
0
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
Example #8
0
    def _set_services(self):
        """Sets the services for this accessory.

        The default implementation adds only the AccessoryInformation services
        and sets its Name characteristic to the Accessory's display name.
        """
        info_service = get_serv_loader().get("AccessoryInformation")
        info_service.get_characteristic("Name")\
                    .set_value(self.display_name, False)
        info_service.get_characteristic("Manufacturer")\
                    .set_value("Default-Manufacturer", False)
        info_service.get_characteristic("Model")\
                    .set_value("Default-Model", False)
        info_service.get_characteristic("SerialNumber")\
                    .set_value("Default-SerialNumber", False)
        self.add_service(info_service)
Example #9
0
    def _set_services(self):
        """Add the fan service. Also add optional characteristics to it."""
        super(LightBulb, 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):

        # 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
Example #10
0
    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)
Example #11
0
    def _set_services(self):
        """Sets the services for this accessory.

        The default implementation adds only the AccessoryInformation services
        and sets its Name characteristic to the Accessory's display name.

        @note: When inheriting from Accessory and overriding this method,
            always call the base implementation first, as it reserves IID of
            1 for the Accessory Information service (HAP requirement).
        """
        info_service = get_serv_loader().get("AccessoryInformation")
        info_service.get_characteristic("Name")\
                    .set_value(self.display_name, False)
        info_service.get_characteristic("Manufacturer")\
                    .set_value("Default-Manufacturer", False)
        info_service.get_characteristic("Model")\
                    .set_value("Default-Model", False)
        info_service.get_characteristic("SerialNumber")\
                    .set_value("Default-SerialNumber", False)
        #FIXME: Need to ensure AccessoryInformation is with IID 1.
        self.add_service(info_service)
Example #12
0
    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)
 def test_publish_no_broker(self):
     acc = accessory.Accessory("Test Accessory")
     service = loader.get_serv_loader().get("TemperatureSensor")
     char = service.get_characteristic("CurrentTemperature")
     acc.add_service(service)
     char.set_value(25, should_notify=True)
Example #14
0
 def _set_services(self):
     """Call the base method and add the BridgingState Service."""
     super(Bridge, self)._set_services()
     self.add_service(
         get_serv_loader().get("BridgingState"))
Example #15
0
 def _set_services(self):
     super(DisplaySwitch, self)._set_services()
     self.add_service(loader.get_serv_loader().get("Switch"))
Example #16
0
 def add_preload_service(self, service):
     """Define the services to be available for the accessory."""
     from pyhap.loader import get_serv_loader
     self.add_service(get_serv_loader().get(service))
Example #17
0
	def _set_services(self):
		super(PiPlaylist, self)._set_services()
		service_loader = loader.get_serv_loader()
		switch = service_loader.get("Switch")
		self.add_service(switch)
Example #18
0
 def _set_services(self):
     super(MotionSensor, self)._set_services()
     self.add_service(loader.get_serv_loader().get("MotionSensor"))
Example #19
0
 def _set_services(self):
     super(AM2302, self)._set_services()
     self.add_service(
         loader.get_serv_loader().get("TemperatureSensor"))
     self.add_service(
         loader.get_serv_loader().get("HumiditySensor"))
Example #20
0
 def _set_services(self):
     super(TSL2591, self)._set_services()
     self.add_service(loader.get_serv_loader().get("LightSensor"))
Example #21
0
 def add_preload_service(self, service):
     """Define the services to be available for the accessory."""
     from pyhap.loader import get_serv_loader
     self.add_service(get_serv_loader().get(service))
Example #22
0
    def _set_services(self):
        super(LightBulb, self)._set_services()

        bulb_service = loader.get_serv_loader().get("Lightbulb")
        self.add_service(bulb_service)
        bulb_service.get_characteristic("On").setter_callback = self.set_bulb
Example #23
0
 def _set_services(self):
     """Add the Switch service."""
     super(ShutdownSwitch, self)._set_services()
     service_loader = loader.get_serv_loader()
     self.add_service(service_loader.get("Switch"))
Example #24
0
 def _set_services(self):
     super(Http, self)._set_services()
     ldr = loader.get_serv_loader()
     for s in self.hapServices:
         self.add_service(ldr.get(s))
Example #25
0
 def _set_services(self):
     super(BMP180, self)._set_services()
     self.add_service(loader.get_serv_loader().get("TemperatureSensor"))