Beispiel #1
0
 def test_getPwmSwitchPacket(self):
     self.assertEqual(ControlPacketsGenerator.getPwmSwitchPacket(0),
                      [1, 0, 1, 0, 0])
     self.assertEqual(ControlPacketsGenerator.getPwmSwitchPacket(0.33),
                      [1, 0, 1, 0, 33])
     self.assertEqual(ControlPacketsGenerator.getPwmSwitchPacket(0.66),
                      [1, 0, 1, 0, 66])
     self.assertEqual(ControlPacketsGenerator.getPwmSwitchPacket(1),
                      [1, 0, 1, 0, 100])
Beispiel #2
0
 def test_getSwitchStatePacket(self):
     self.assertEqual(ControlPacketsGenerator.getSwitchStatePacket(0.0),
                      [0, 0, 1, 0, 0])
     self.assertEqual(ControlPacketsGenerator.getSwitchStatePacket(1),
                      [0, 0, 1, 0, 100])
     self.assertEqual(ControlPacketsGenerator.getSwitchStatePacket(0.99),
                      [0, 0, 1, 0, 99])
     self.assertEqual(ControlPacketsGenerator.getSwitchStatePacket(0.4),
                      [0, 0, 1, 0, 40])
Beispiel #3
0
 def test_getKeepAliveStatePacket(self):
     self.assertEqual(
         ControlPacketsGenerator.getKeepAliveStatePacket(False, 1, 135),
         [6, 0, 4, 0, 0, 100, 135, 0])
     self.assertEqual(
         ControlPacketsGenerator.getKeepAliveStatePacket(True, 1, 0),
         [6, 0, 4, 0, 1, 100, 0, 0])
     self.assertEqual(
         ControlPacketsGenerator.getKeepAliveStatePacket(True, 0, 500),
         [6, 0, 4, 0, 1, 0, 244, 1])
    def _writeFastSetup(self, crownstoneId, meshAccessAddress, ibeaconUUID,
                        ibeaconMajor, ibeaconMinor):
        packet = ControlPacketsGenerator.getSetupPacket(
            0, crownstoneId, self.core.settings.adminKey,
            self.core.settings.memberKey, self.core.settings.guestKey,
            meshAccessAddress, ibeaconUUID, ibeaconMajor, ibeaconMinor)

        print("BluenetBLE: Writing setup data to Crownstone...")
        self.core.ble.writeToCharacteristic(CSServices.SetupService,
                                            SetupCharacteristics.SetupControl,
                                            packet)
Beispiel #5
0
 def disconnect(self):
     """
       This forces the Crownstone to disconnect from you
     """
     try:
         self._writeControlPacket(
             ControlPacketsGenerator.getDisconnectPacket())
         self.core.ble.disconnect()
     except BTLEException as err:
         if err.code is BTLEException.DISCONNECTED:
             pass
         else:
             raise err
Beispiel #6
0
    def _writeFastSetupV2(self, sphereId, crownstoneId, meshDeviceKey,
                          ibeaconUUID, ibeaconMajor, ibeaconMinor):
        packet = ControlPacketsGenerator.getSetupPacket(
            crownstoneId, sphereId, self.core.settings.adminKey,
            self.core.settings.memberKey, self.core.settings.basicKey,
            self.core.settings.serviceDataKey,
            self.core.settings.localizationKey, meshDeviceKey,
            self.core.settings.meshApplicationKey,
            self.core.settings.meshNetworkKey, ibeaconUUID, ibeaconMajor,
            ibeaconMinor)

        print("BluenetBLE: Writing setup data to Crownstone...")
        self.core.ble.writeToCharacteristic(CSServices.SetupService,
                                            SetupCharacteristics.SetupControl,
                                            packet)
 def switchRelay(self, switchState):
     """
      :param switchState: number 0 is off, 1 is on.
     """
     self._writeControlPacket(ControlPacketsGenerator.getRelaySwitchPacket(switchState))
 def switchPWM(self, switchState):
     """
      :param switchState: number [0..1]
     """
     self._writeControlPacket(ControlPacketsGenerator.getPwmSwitchPacket(switchState))
Beispiel #9
0
 def test_getSetSchedulePacket(self):
     self.assertEqual(
         ControlPacketsGenerator.getSetSchedulePacket([1, 2, 3]),
         [15, 0, 3, 0, 1, 2, 3])
Beispiel #10
0
 def _recoveryByFactoryReset(self):
     packet = ControlPacketsGenerator.getFactoryResetPacket()
     return self.core.ble.writeToCharacteristicWithoutEncryption(
         CSServices.CrownstoneService,
         CrownstoneCharacteristics.FactoryReset, packet)
Beispiel #11
0
 def test_getAllowDimmingPacket(self):
     self.assertEqual(ControlPacketsGenerator.getAllowDimmingPacket(True),
                      [29, 0, 1, 0, 1])
     self.assertEqual(ControlPacketsGenerator.getAllowDimmingPacket(False),
                      [29, 0, 1, 0, 0])
Beispiel #12
0
 def test_getScheduleRemovePacket(self):
     self.assertEqual(ControlPacketsGenerator.getScheduleRemovePacket(2),
                      [26, 0, 1, 0, 2])
Beispiel #13
0
 def test_getFactoryResetPacket(self):
     self.assertEqual(ControlPacketsGenerator.getFactoryResetPacket(),
                      [239, 190, 173, 222])
Beispiel #14
0
 def test_getPutInDFUPacket(self):
     self.assertEqual(ControlPacketsGenerator.getPutInDFUPacket(),
                      [3, 0, 0, 0])
 def disconnect(self):
     """
       This forces the Crownstone to disconnect from you
     """
     self._writeControlPacket(ControlPacketsGenerator.getDisconnectPacket())
     self.core.ble.disconnect()
 def reset(self):
     self._writeControlPacket(ControlPacketsGenerator.getResetPacket())
Beispiel #17
0
 def test_getCommandFactoryResetPacket(self):
     self.assertEqual(
         ControlPacketsGenerator.getCommandFactoryResetPacket(),
         [5, 0, 4, 0, 239, 190, 173, 222])
Beispiel #18
0
 def test_getRelaySwitchPacket(self):
     self.assertEqual(ControlPacketsGenerator.getRelaySwitchPacket(0),
                      [16, 0, 1, 0, 0])
     self.assertEqual(ControlPacketsGenerator.getRelaySwitchPacket(1),
                      [16, 0, 1, 0, 1])
Beispiel #19
0
 def test_getDisconnectPacket(self):
     self.assertEqual(ControlPacketsGenerator.getDisconnectPacket(),
                      [19, 0, 0, 0])
 def commandFactoryReset(self):
     """
       If you have the keys, you can use this to put the crownstone back into factory default mode
     """
     self._writeControlPacket(ControlPacketsGenerator.getCommandFactoryResetPacket())
Beispiel #21
0
 def test_getSetTimePacket(self):
     self.assertEqual(ControlPacketsGenerator.getSetTimePacket(1516616561),
                      [2, 0, 4, 0, 113, 187, 101, 90])
 def allowDimming(self, allow):
     """
     :param allow: bool
     """
     self._writeControlPacket(ControlPacketsGenerator.getAllowDimmingPacket(allow))
Beispiel #23
0
 def test_getResetPacket(self):
     self.assertEqual(ControlPacketsGenerator.getResetPacket(),
                      [4, 0, 0, 0])
 def lockSwitch(self, lock):
     """
     :param lock: bool
     """
     self._writeControlPacket(ControlPacketsGenerator.getLockSwitchPacket(lock))
Beispiel #25
0
 def test_getKeepAliveRepeatPacket(self):
     self.assertEqual(ControlPacketsGenerator.getKeepAliveRepeatPacket(),
                      [7, 0, 0, 0])
Beispiel #26
0
 def test_getResetErrorPacket(self):
     self.assertEqual(
         ControlPacketsGenerator.getResetErrorPacket(0xabcdef02),
         [23, 0, 4, 0, 2, 239, 205, 171])
Beispiel #27
0
 def test_getLockSwitchPacket(self):
     self.assertEqual(ControlPacketsGenerator.getLockSwitchPacket(True),
                      [30, 0, 1, 0, 1])
     self.assertEqual(ControlPacketsGenerator.getLockSwitchPacket(False),
                      [30, 0, 1, 0, 0])