Esempio n. 1
0
 def dnd_status(self):
     """Returns do-not-disturb status."""
     status = self.send("get_notdisturb")
     return DNDStatus(
         dict(
             enabled=status[0],
             start_hour=status[1],
             start_minute=status[2],
             end_hour=status[3],
             end_minute=status[4],
         ))
Esempio n. 2
0
 def test_parse_forbid_mode2(self):
     status = self.device.status()
     value = '{"time":[82080,33300,0],"tz":3,"tzs":10800}'
     expected_value = DNDStatus(
         dict(
             enabled=False,
             start_hour=22,
             start_minute=48,
             end_hour=9,
             end_minute=15,
         ))
     assert str(status._parse_forbid_mode(value)) == str(expected_value)
Esempio n. 3
0
 def test_parse_forbid_mode(self):
     status = self.device.status()
     value = '{"time":[75600,21600,1],"tz":2,"tzs":7200}'
     expected_value = DNDStatus(
         dict(
             enabled=True,
             start_hour=21,
             start_minute=0,
             end_hour=6,
             end_minute=0,
         ))
     assert str(status._parse_forbid_mode(value)) == str(expected_value)
Esempio n. 4
0
    def _parse_forbid_mode(self, val) -> DNDStatus:
        # Example data: {"time":[75600,21600,1],"tz":2,"tzs":7200}
        def _seconds_to_components(val):
            hour = math.floor(val / 3600)
            minut = math.floor((val - hour * 3600) / 60)
            return (hour, minut)

        as_dict = json.loads(val)
        enabled = bool(as_dict["time"][2])
        start = _seconds_to_components(as_dict["time"][0])
        end = _seconds_to_components(as_dict["time"][1])
        return DNDStatus(
            dict(
                enabled=enabled,
                start_hour=start[0],
                start_minute=start[1],
                end_hour=end[0],
                end_minute=end[1],
            ))