Ejemplo n.º 1
0
 def test_handleAction_toggle_off_to_on(self, publish):
     self.shelly.turnOff()
     self.assertTrue(self.shelly.isOff())
     toggle = IndigoAction(indigo.kDeviceAction.Toggle)
     self.shelly.handleAction(toggle)
     self.assertTrue(self.shelly.isOn())
     publish.assert_called_with(
         "shellies/shelly-bulb-test/light/0/set",
         json.dumps({
             "turn": "on",
             "mode": "color",
             "white": 100,
             "red": 0,
             "green": 0,
             "blue": 0,
             "gain": 100
         }))
Ejemplo n.º 2
0
 def test_handleAction_turn_off(self, publish):
     self.shelly.turnOn()
     self.assertTrue(self.shelly.isOn())
     turnOff = IndigoAction(indigo.kDeviceAction.TurnOff)
     self.shelly.handleAction(turnOff)
     self.assertTrue(self.shelly.isOff())
     publish.assert_called_with(
         "shellies/shelly-rgbw2-color-test/color/0/set",
         json.dumps({
             "turn": "off",
             "mode": "color",
             "white": 100,
             "red": 0,
             "green": 0,
             "blue": 0,
             "gain": 0
         }))
    def test_handleAction_dimBy(self, publish):
        self.shelly.device.updateStateOnServer('brightnessLevel', 100)
        dimBy = IndigoAction(indigo.kDeviceAction.DimBy, actionValue=25)

        self.shelly.handleAction(dimBy)
        self.assertTrue(self.shelly.isOn())
        self.assertEqual(75, self.shelly.device.states['brightnessLevel'])
        publish.assert_called_with(
            "shellies/shelly-bulb-vintage-test/light/0/set",
            '{"turn": "on", "brightness": 75}')

        self.shelly.handleAction(dimBy)
        self.assertTrue(self.shelly.isOn())
        self.assertEqual(50, self.shelly.device.states['brightnessLevel'])
        publish.assert_called_with(
            "shellies/shelly-bulb-vintage-test/light/0/set",
            '{"turn": "on", "brightness": 50}')
    def test_handleAction_setColorLevels(self, publish):
        self.shelly.turnOn()
        self.shelly.device.updateStateOnServer('brightnessLevel', 100)
        self.shelly.device.updateStateOnServer('whiteLevel', 10)
        self.shelly.device.updateStateOnServer('whiteTemperature', 10)
        setColorLevels = IndigoAction(indigo.kDeviceAction.SetColorLevels,
                                      actionValue={
                                          'whiteLevel': 50,
                                          'whiteTemperature': 6500
                                      })

        self.shelly.handleAction(setColorLevels)
        self.assertTrue(self.shelly.isOn())
        self.assertEqual(50, self.shelly.device.states['whiteLevel'])
        self.assertEqual(6500, self.shelly.device.states['whiteTemperature'])
        publish.assert_called_with(
            "shellies/shelly-bulb-duo-test/light/0/set",
            '{"turn": "on", "temp": 6500, "brightness": 100}')
    def test_handleAction_brightenBy(self, publish):
        self.assertEqual(0, self.shelly.device.states['brightnessLevel'])
        brightenBy = IndigoAction(indigo.kDeviceAction.BrightenBy,
                                  actionValue=25)

        self.shelly.handleAction(brightenBy)
        self.assertTrue(self.shelly.isOn())
        self.assertEqual(25, self.shelly.device.states['brightnessLevel'])
        publish.assert_called_with(
            "shellies/shelly-bulb-duo-test/light/0/set",
            '{"turn": "on", "temp": 2700, "brightness": 25}')

        self.shelly.handleAction(brightenBy)
        self.assertTrue(self.shelly.isOn())
        self.assertEqual(50, self.shelly.device.states['brightnessLevel'])
        publish.assert_called_with(
            "shellies/shelly-bulb-duo-test/light/0/set",
            '{"turn": "on", "temp": 2700, "brightness": 50}')
Ejemplo n.º 6
0
    def test_handleAction_dimBy_less_than_0(self, publish):
        self.shelly.device.updateStateOnServer('brightnessLevel', 10)
        dimBy = IndigoAction(indigo.kDeviceAction.DimBy, actionValue=25)

        self.shelly.handleAction(dimBy)
        self.assertTrue(self.shelly.isOff())
        self.assertEqual(0, self.shelly.device.states['brightnessLevel'])
        publish.assert_called_with(
            "shellies/shelly-bulb-test/light/0/set",
            json.dumps({
                "turn": "off",
                "mode": "color",
                "white": 100,
                "red": 0,
                "green": 0,
                "blue": 0,
                "gain": 0
            }))
Ejemplo n.º 7
0
    def test_handleAction_setBrightness(self, publish):
        self.assertEqual(0, self.shelly.device.states['brightnessLevel'])
        setBrightness = IndigoAction(indigo.kDeviceAction.SetBrightness,
                                     actionValue=50)

        self.shelly.handleAction(setBrightness)
        self.assertTrue(self.shelly.isOn())
        self.assertEqual(50, self.shelly.device.states['brightnessLevel'])
        publish.assert_called_with(
            "shellies/shelly-bulb-test/light/0/set",
            json.dumps({
                "turn": "on",
                "mode": "color",
                "white": 100,
                "red": 0,
                "green": 0,
                "blue": 0,
                "gain": 50
            }))
Ejemplo n.º 8
0
    def test_handleAction_brightenBy_more_than_100(self, publish):
        self.shelly.device.updateStateOnServer('brightnessLevel', 90)
        brightenBy = IndigoAction(indigo.kDeviceAction.BrightenBy,
                                  actionValue=25)

        self.shelly.handleAction(brightenBy)
        self.assertTrue(self.shelly.isOn())
        self.assertEqual(100, self.shelly.device.states['brightnessLevel'])
        publish.assert_called_with(
            "shellies/shelly-rgbw2-color-test/color/0/set",
            json.dumps({
                "turn": "on",
                "mode": "color",
                "white": 100,
                "red": 0,
                "green": 0,
                "blue": 0,
                "gain": 100
            }))
Ejemplo n.º 9
0
 def test_sendStatusRequestCommand(self, publish):
     statusRequest = IndigoAction(indigo.kDeviceAction.RequestStatus)
     self.shelly.handleAction(statusRequest)
     publish.assert_called_with("shellies/shelly-gas-test/command", "update")
Ejemplo n.º 10
0
 def test_handleAction_update_energy(self, publish):
     updateEnergy = IndigoAction(indigo.kDeviceAction.RequestStatus)
     self.shelly.handleAction(updateEnergy)
     publish.assert_called_with("shellies/shelly-plug-test/command",
                                "update")
 def test_handleAction_status_request(self, publish):
     statusRequest = IndigoAction(indigo.kDeviceAction.RequestStatus)
     self.shelly.handleAction(statusRequest)
     publish.assert_called_with("shellies/shelly-bulb-duo-test/command",
                                "update")
Ejemplo n.º 12
0
 def test_handleAction_update_energy(self, publish):
     updateEnergy = IndigoAction(indigo.kUniversalAction.EnergyUpdate)
     self.shelly.handleAction(updateEnergy)
     publish.assert_called_with("shellies/shelly-em-meter-test/command",
                                "update")
Ejemplo n.º 13
0
 def test_handleAction_reset_energy(self):
     self.shelly.updateEnergy(30)
     self.assertAlmostEqual(0.0005, self.shelly.device.states['accumEnergyTotal'], 4)
     resetEnergy = IndigoAction(indigo.kUniversalAction.EnergyReset)
     self.shelly.handleAction(resetEnergy)
     self.assertAlmostEqual(0.0000, self.shelly.device.states['accumEnergyTotal'], 4)