Skip to content

Commit

Permalink
Change brightness to always display in percentage to be consistent (#170
Browse files Browse the repository at this point in the history
)
  • Loading branch information
bdraco authored Nov 22, 2021
1 parent 51e9884 commit 2f83274
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
4 changes: 2 additions & 2 deletions flux_led/base_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,13 +502,13 @@ def __str__(self) -> str: # noqa: C901
if self.rgbwcapable:
mode_str += f" White: {rx.warm_white}"
else:
mode_str += f" Brightness: {self.brightness}"
mode_str += f" Brightness: {round(self.brightness * 100 / 255)}%"
elif color_mode == COLOR_MODE_DIM:
mode_str = f"Warm White: {utils.byteToPercent(rx.warm_white)}%"
elif color_mode == COLOR_MODE_CCT:
cct_value = self.getWhiteTemperature()
mode_str = "CCT: {}K Brightness: {}%".format(
cct_value[0], cct_value[1] / 255
cct_value[0], round(cct_value[1] * 100 / 255)
)
elif mode == MODE_PRESET:
pat = self.effect
Expand Down
32 changes: 15 additions & 17 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def read_data(expected):

self.assertEqual(
light.__str__(),
"ON [Color: (103, 255, 104) Brightness: 255 raw state: 129,69,35,97,33,16,103,255,104,0,4,0,240,61,]",
"ON [Color: (103, 255, 104) Brightness: 100% raw state: 129,69,35,97,33,16,103,255,104,0,4,0,240,61,]",
)
self.assertEqual(light.protocol, PROTOCOL_LEDENET_8BYTE)
self.assertEqual(light.model_num, 0x45)
Expand Down Expand Up @@ -115,7 +115,7 @@ def read_data(expected):

self.assertEqual(
light.__str__(),
"ON [Color: (1, 25, 80) Brightness: 80 raw state: 129,69,35,97,33,16,1,25,80,0,4,0,240,217,]",
"ON [Color: (1, 25, 80) Brightness: 31% raw state: 129,69,35,97,33,16,1,25,80,0,4,0,240,217,]",
)
self.assertEqual(light.protocol, PROTOCOL_LEDENET_8BYTE)
self.assertEqual(light.is_on, True)
Expand Down Expand Up @@ -220,7 +220,7 @@ def read_data(expected):

self.assertEqual(
light.__str__(),
"ON [Color: (182, 0, 152) Brightness: 182 raw state: 129,69,35,97,33,16,182,0,152,0,4,0,240,189,]",
"ON [Color: (182, 0, 152) Brightness: 71% raw state: 129,69,35,97,33,16,182,0,152,0,4,0,240,189,]",
)
self.assertEqual(light.protocol, PROTOCOL_LEDENET_8BYTE)
self.assertEqual(light.is_on, True)
Expand Down Expand Up @@ -345,7 +345,7 @@ def read_data(expected):
self.assertEqual(mock_send.call_args, mock.call(bytearray(LEDENET_STATE_QUERY)))
self.assertEqual(
light.__str__(),
"OFF [Color: (255, 91, 212) Brightness: 255 raw state: 129,69,36,97,33,16,255,91,212,0,4,0,240,158,]",
"OFF [Color: (255, 91, 212) Brightness: 100% raw state: 129,69,36,97,33,16,255,91,212,0,4,0,240,158,]",
)
self.assertEqual(light.protocol, PROTOCOL_LEDENET_8BYTE)
self.assertEqual(light.is_on, False)
Expand All @@ -361,7 +361,7 @@ def read_data(expected):
self.assertEqual(mock_send.call_args, mock.call(bytearray(b"q#\x0f\xa3")))
self.assertEqual(
light.__str__(),
"ON [Color: (255, 91, 212) Brightness: 255 raw state: 129,69,35,97,33,16,255,91,212,0,4,0,240,158,]",
"ON [Color: (255, 91, 212) Brightness: 100% raw state: 129,69,35,97,33,16,255,91,212,0,4,0,240,158,]",
)
self.assertEqual(light.protocol, PROTOCOL_LEDENET_8BYTE)
self.assertEqual(light.is_on, True)
Expand All @@ -378,7 +378,7 @@ def read_data(expected):
)
self.assertEqual(
light.__str__(),
"ON [Color: (3, 77, 247) Brightness: 247 raw state: 129,69,35,97,33,16,3,77,247,0,4,0,240,158,]",
"ON [Color: (3, 77, 247) Brightness: 97% raw state: 129,69,35,97,33,16,3,77,247,0,4,0,240,158,]",
)
self.assertEqual(light.protocol, PROTOCOL_LEDENET_8BYTE)
self.assertEqual(light.is_on, True)
Expand All @@ -394,7 +394,7 @@ def read_data(expected):
self.assertEqual(mock_send.call_args, mock.call(bytearray(LEDENET_STATE_QUERY)))
self.assertEqual(
light.__str__(),
"ON [Color: (3, 77, 247) Brightness: 247 raw state: 129,69,35,97,33,16,3,77,247,0,4,0,240,182,]",
"ON [Color: (3, 77, 247) Brightness: 97% raw state: 129,69,35,97,33,16,3,77,247,0,4,0,240,182,]",
)
self.assertEqual(light.protocol, PROTOCOL_LEDENET_8BYTE)
self.assertEqual(light.is_on, True)
Expand Down Expand Up @@ -597,7 +597,7 @@ def read_data(expected):

self.assertEqual(
light.__str__(),
"ON [Color: (1, 25, 80) Brightness: 80 raw state: 102,1,35,65,33,8,1,25,80,1,153,]",
"ON [Color: (1, 25, 80) Brightness: 31% raw state: 102,1,35,65,33,8,1,25,80,1,153,]",
)
self.assertEqual(light.protocol, PROTOCOL_LEDENET_ORIGINAL)
self.assertEqual(light.is_on, True)
Expand All @@ -619,7 +619,7 @@ def read_data(expected):

self.assertEqual(
light.__str__(),
"OFF [Color: (1, 25, 80) Brightness: 80 raw state: 102,1,36,65,33,8,1,25,80,1,153,]",
"OFF [Color: (1, 25, 80) Brightness: 31% raw state: 102,1,36,65,33,8,1,25,80,1,153,]",
)
self.assertEqual(light.protocol, PROTOCOL_LEDENET_ORIGINAL)
self.assertEqual(light.is_on, False)
Expand All @@ -641,7 +641,7 @@ def read_data(expected):

self.assertEqual(
light.__str__(),
"ON [Color: (1, 25, 80) Brightness: 80 raw state: 102,1,35,65,33,8,1,25,80,1,153,]",
"ON [Color: (1, 25, 80) Brightness: 31% raw state: 102,1,35,65,33,8,1,25,80,1,153,]",
)
self.assertEqual(light.protocol, PROTOCOL_LEDENET_ORIGINAL)
self.assertEqual(light.is_on, True)
Expand Down Expand Up @@ -705,7 +705,7 @@ def read_data(expected):

self.assertEqual(
light.__str__(),
"ON [Color: (1, 25, 80) Brightness: 80 raw state: 129,69,35,97,33,16,1,25,80,0,4,0,240,217,]",
"ON [Color: (1, 25, 80) Brightness: 31% raw state: 129,69,35,97,33,16,1,25,80,0,4,0,240,217,]",
)
self.assertEqual(light.protocol, PROTOCOL_LEDENET_8BYTE)
self.assertEqual(light.is_on, True)
Expand Down Expand Up @@ -784,7 +784,7 @@ def read_data(expected):
self.assertEqual(light.getWhiteTemperature(), (6500, 255))
self.assertEqual(
light.__str__(),
"ON [CCT: 6500K Brightness: 1.0% raw state: 129,222,35,65,71,0,0,0,0,0,2,255,0,11,]",
"ON [CCT: 6500K Brightness: 100% raw state: 129,222,35,65,71,0,0,0,0,0,2,255,0,11,]",
)

@patch("flux_led.WifiLedBulb._send_msg")
Expand Down Expand Up @@ -873,9 +873,7 @@ def read_data(expected):
mock_read.side_effect = read_data
light = flux_led.WifiLedBulb("192.168.1.164")
self.assertEqual(light.model_num, 0x41)
self.assertEqual(
light.model, "Single Channel Controller (0x41)"
)
self.assertEqual(light.model, "Single Channel Controller (0x41)")
assert light.color_modes == {COLOR_MODE_DIM}

self.assertEqual(mock_read.call_count, 2)
Expand Down Expand Up @@ -984,7 +982,7 @@ def read_data(expected):

self.assertEqual(
light.__str__(),
"ON [Color: (255, 0, 0) Brightness: 255 raw state: 129,162,35,97,65,16,255,0,0,0,4,0,240,235,]",
"ON [Color: (255, 0, 0) Brightness: 100% raw state: 129,162,35,97,65,16,255,0,0,0,4,0,240,235,]",
)
self.assertEqual(light.protocol, PROTOCOL_LEDENET_ADDRESSABLE)
self.assertEqual(light.is_on, True)
Expand Down Expand Up @@ -1062,7 +1060,7 @@ def read_data(expected):

self.assertEqual(
light.__str__(),
"ON [Color: (255, 0, 0) Brightness: 255 raw state: 129,161,35,97,65,16,255,0,0,0,4,0,240,234,]",
"ON [Color: (255, 0, 0) Brightness: 100% raw state: 129,161,35,97,65,16,255,0,0,0,4,0,240,234,]",
)
self.assertEqual(light.protocol, PROTOCOL_LEDENET_ORIGINAL_ADDRESSABLE)
self.assertEqual(light.is_on, True)
Expand Down

0 comments on commit 2f83274

Please sign in to comment.