Esempio n. 1
0
	def lighting_group_ramp(self, source_addr, group_addr, duration, level=1.0):
		"""
		Ramps (fades) a group address to a specified lighting level.

		Note: CBus only supports a limited number of fade durations, in decreasing
		accuracy up to 17 minutes (1020 seconds).  Durations longer than this will
		throw an error.
		
		A duration of 0 will ramp "instantly" to the given level.

		:param source_addr: Source address of the event.
		:type source_addr: int

		:param group_id: The group address to ramp.
		:type group_id: int
		
		:param duration: Duration, in seconds, that the ramp should occur over.
		:type duration: int
		
		:param level: An amount between 0.0 and 1.0 indicating the brightness to set.
		:type level: float
		
		:returns: Single-byte string with code for the confirmation event.
		:rtype: string
		
		"""
		p = PointToMultipointPacket(application=APP_LIGHTING)
		p.source_address = source_addr
		p.sal.append(LightingRampSAL(p, group_addr, duration, level))
		p.checksum = self.checksum
		return self._send(p)
Esempio n. 2
0
    def test_lighting_encode_decode(self):
        """test of encode then decode"""

        orig = PointToMultipointPacket(sals=LightingOnSAL(27))
        orig.source_address = 5

        data = orig.encode_packet() + b'\r\n'

        d = self.decode_pm(data)
        self.assertEqual(orig.source_address, d.source_address)
        self.assertEqual(len(orig), len(d))

        self.assertIsInstance(d[0], LightingOnSAL)
        self.assertEqual(orig[0].group_address, d[0].group_address)
Esempio n. 3
0
    def on_clock_update(self, val):
        """
        Event called when a clock application "update time" is recieved.

        :param variable: Clock variable to update.
        :type variable: int

        :param val: Clock value
        :type variable: datetime.date or datetime.time
        """
        logger.debug("recv: clock update: %r" % val)

        # DEBUG: randomly trigger lights
        p = PointToMultipointPacket(self.checksum,
                                    sals=LightingOnSAL(random.randint(1, 100)))
        p.source_address = random.randint(1, 100)

        self._send_later(p)

        p = PointToMultipointPacket(self.checksum,
                                    sals=LightingOffSAL(random.randint(1,
                                                                       100)))
        p.source_address = random.randint(1, 100)
        self._send_later(p)
Esempio n. 4
0
    def lighting_group_terminate_ramp(self, source_addr, group_addr):
        """
        Stops ramping a group address at the current point.

        :param source_addr: Source address of the event.
        :type source_addr: int

        :param group_addr: Group address to stop ramping of.
        :type group_addr: int

        :returns: Single-byte string with code for the confirmation event.
        :rtype: string
        """
        p = PointToMultipointPacket(checksum=self.checksum,
                                    sals=LightingTerminateRampSAL(group_addr))
        p.source_address = source_addr
        return self._send(p)
Esempio n. 5
0
	def lighting_group_terminate_ramp(self, source_addr, group_addr):
		"""
		Stops ramping a group address at the current point.
		
		:param source_addr: Source address of the event.
		:type source_addr: int
		
		:param group_addr: Group address to stop ramping of.
		:type group_addr: int
		
		:returns: Single-byte string with code for the confirmation event.
		:rtype: string
		"""
		p = PointToMultipointPacket(application=APP_LIGHTING)
		p.source_address = source_addr
		p.sal.append(LightingTerminateRampSAL(p, group_addr))
		p.checksum = self.checksum
		return self._send(p)
Esempio n. 6
0
    def lighting_group_off(self, source_addr, group_addr):
        """
        Turns off the lights for the given group_addr.

        :param source_addr: Source address of the event.
        :type source_addr: int

        :param group_addr: Group address to turn the lights on for.
        :type group_addr: int

        :returns: Single-byte string with code for the confirmation event.
        :rtype: string

        """
        p = PointToMultipointPacket(checksum=self.checksum,
                                    sals=LightingOffSAL(group_addr))
        p.source_address = source_addr
        return self._send(p)
Esempio n. 7
0
	def lighting_group_off(self, source_addr, group_addr):
		"""
		Turns off the lights for the given group_id.
		
		:param source_addr: Source address of the event.
		:type source_addr: int	
		
		:param group_id: Group address to turn the lights on for.
		:type group_id: int
		
		:returns: Single-byte string with code for the confirmation event.
		:rtype: string
				
		"""
		p = PointToMultipointPacket(application=APP_LIGHTING)
		p.source_address = source_addr
		p.sal.append(LightingOffSAL(p, group_addr))
		p.checksum = self.checksum
		return self._send(p)
Esempio n. 8
0
    def test_temperature_encode_decode(self):
        """self-made tests of encode then decode"""

        orig = PointToMultipointPacket(sals=[
            TemperatureBroadcastSAL(10, 0.5),
            TemperatureBroadcastSAL(11, 56)
        ])
        orig.source_address = 5
        data = orig.encode_packet() + b'\r\n'

        d = self.decode_pm(data)
        self.assertIsInstance(orig, PointToMultipointPacket)
        self.assertEqual(orig.source_address, d.source_address)
        self.assertEqual(len(orig), len(d))

        for x in range(len(d)):
            self.assertIsInstance(d[x], TemperatureBroadcastSAL)
            self.assertEqual(orig[x].group_address, d[x].group_address)
            self.assertEqual(orig[x].temperature, d[x].temperature)
Esempio n. 9
0
def lighting_encode_decode_test():
    "self-made tests of encode then decode"

    orig = PointToMultipointPacket(application=APP_LIGHTING)
    orig.source_address = 5
    orig.sal.append(LightingOnSAL(orig, 27))

    data = orig.encode()

    d, r = decode_packet(data)
    assert isinstance(orig, PointToMultipointPacket)
    assert orig.source_address == d.source_address
    assert len(orig.sal) == len(d.sal)

    assert isinstance(d.sal[0], LightingOnSAL)
    assert orig.sal[0].group_address == d.sal[0].group_address

    # ensure there is no remaining data to be parsed
    assert r == None
Esempio n. 10
0
def lighting_encode_decode_test():
	"self-made tests of encode then decode"
	
	orig = PointToMultipointPacket(application=APP_LIGHTING)
	orig.source_address = 5
	orig.sal.append(LightingOnSAL(orig, 27))
	
	data = orig.encode()

	d, r = decode_packet(data)
	assert isinstance(orig, PointToMultipointPacket)		
	assert orig.source_address == d.source_address
	assert len(orig.sal) == len(d.sal)
	
	assert isinstance(d.sal[0], LightingOnSAL)
	assert orig.sal[0].group_address == d.sal[0].group_address
	
	# ensure there is no remaining data to be parsed
	assert r == None
Esempio n. 11
0
def temperature_encode_decode_test():
	"self-made tests of encode then decode"
	
	orig = PointToMultipointPacket(application=APP_TEMPERATURE)
	orig.source_address = 5
	orig.sal.append(TemperatureBroadcastSAL(orig, 10, 0.5))
	orig.sal.append(TemperatureBroadcastSAL(orig, 11, 56))
	
	data = orig.encode()

	d, r = decode_packet(data)
	assert isinstance(orig, PointToMultipointPacket)		
	assert orig.source_address == d.source_address
	assert len(orig.sal) == len(d.sal)
	
	for x in range(len(d.sal)):
		assert isinstance(d.sal[x], TemperatureBroadcastSAL)
		assert orig.sal[x].group_address == d.sal[x].group_address
		assert orig.sal[x].temperature == d.sal[x].temperature
	
	# ensure there is no remaining data to be parsed
	assert r == None
Esempio n. 12
0
def temperature_encode_decode_test():
    "self-made tests of encode then decode"

    orig = PointToMultipointPacket(application=APP_TEMPERATURE)
    orig.source_address = 5
    orig.sal.append(TemperatureBroadcastSAL(orig, 10, 0.5))
    orig.sal.append(TemperatureBroadcastSAL(orig, 11, 56))

    data = orig.encode()

    d, r = decode_packet(data)
    assert isinstance(orig, PointToMultipointPacket)
    assert orig.source_address == d.source_address
    assert len(orig.sal) == len(d.sal)

    for x in range(len(d.sal)):
        assert isinstance(d.sal[x], TemperatureBroadcastSAL)
        assert orig.sal[x].group_address == d.sal[x].group_address
        assert orig.sal[x].temperature == d.sal[x].temperature

    # ensure there is no remaining data to be parsed
    assert r == None