def createPoint(self, room_name, configuration, comm_service):
        point_name = configuration.get(CONFIG_POINT_NAME)
        if point_name is None or point_name == "":
            raise ValueError("Unknown point in room {}".format(room_name))
        if room_name is None or room_name == "":
            raise ValueError(
                "Point {} to be added to unknown room".format(configuration))

        point_id = NAME_SEPARATOR + room_name + NAME_SEPARATOR + point_name

        ctlPin = configuration.get(CONFIG_POINT_CONTROLPIN)
        if ctlPin is None or ctlPin == "":
            raise ValueError("Point {} does not have {} defined".format(
                point_id, CONFIG_POINT_CONTROLPIN))
        btnPin = configuration.get(CONFIG_POINT_BUTTONPIN)
        if btnPin is None or btnPin == "":
            raise ValueError("Point {} does not have {} defined".format(
                point_id, CONFIG_POINT_BUTTONPIN))

        point_type = configuration.get(CONFIG_POINT_TYPE)
        if point_type == CONFIG_POINT_TYPE_LIGHT:
            point = LightPoint(id=point_id,
                               controlPin=ctlPin,
                               buttonPin=btnPin,
                               comm_service=comm_service)
            point.initialize()
            return point
        else:
            raise ValueError("Unrecognized point type: {}".format(point_type))
Example #2
0
    def test_updateStatus_Any(self):
        led = Mock()
        point = LightPoint(id="/RoomB/PointYU",
                           controlPin=9,
                           buttonPin=10,
                           comm_service=None)
        point.led = led

        point.updateStatus(message="AnyMessage")

        led.on.assert_not_called()
Example #3
0
    def test_updateStatus_Off(self):
        led = Mock()
        point = LightPoint(id="/RoomB/PointYU",
                           controlPin=7,
                           buttonPin=8,
                           comm_service=None)
        point.led = led

        point.updateStatus(message="ON")

        led.on.assert_called()
Example #4
0
    def test_enable(self):
        led = Mock()
        point = LightPoint(id="/RoomB/PointYU",
                           controlPin=11,
                           buttonPin=12,
                           comm_service=None)
        point.led = led

        point.enable()

        led.on.assert_called()
        led.off.assert_not_called()
Example #5
0
    def test_reset(self):
        led = Mock()
        comm_service = Mock()
        point = LightPoint(id="/RoomB/PointYU",
                           controlPin=11,
                           buttonPin=12,
                           comm_service=comm_service)
        point.led = led

        point.reset()

        led.on.assert_not_called()
        led.off.assert_called()
        comm_service.sendStatusUpdate.assert_called()
Example #6
0
    def test_notifyCurrentState_On(self):
        comm_srv = Mock()
        led = Mock()
        led.value = 1
        point = LightPoint(id="/RoomB/PointYU",
                           controlPin=1,
                           buttonPin=2,
                           comm_service=comm_srv)
        point.led = led

        point.notifyCurrentState()

        comm_srv.sendStatusUpdate.assert_called_with(point_id="/RoomB/PointYU",
                                                     message="ON")
Example #7
0
    def test_toggle_to_on(self):
        led = Mock()
        led.value = 0
        comm_srv = Mock()
        point = LightPoint(id="/RoomB/PointYU",
                           controlPin=17,
                           buttonPin=18,
                           comm_service=comm_srv)
        point.led = led

        point.toggle()

        led.off.assert_not_called()
        led.on.assert_called()
        comm_srv.sendStatusUpdate.assert_called()