예제 #1
0
 def test_add_method_should_append_notification_to_list_and_return_uuid(
         self, uuid4):
     result = Notifications.add('warning', 'No title', 'No text')
     self.assertEqual(result, 'in-test')
     expected_list = self.notifications[:]
     expected_list.append({
         'uuid': 'in-test',
         'type': 'warning',
         'title': 'No title',
         'text': 'No text'
     })
     self.assertEqual(Notifications.list(), expected_list)
예제 #2
0
 def test_remove_method_when_no_such_notification_in_list_should_do_nothing(
         self):
     Notifications.remove('0de8916f-7595-41b0-8e46-c9eea962b0b8')
     self.assertEqual(Notifications.list(), self.notifications)
예제 #3
0
 def test_remove_method_should_remove_notification_from_list(self):
     Notifications.remove('second')
     expected_list = self.notifications[:1]
     self.assertEqual(Notifications.list(), expected_list)
예제 #4
0
 def test_list_method_should_return_proper_notifications_list(self):
     self.assertEqual(Notifications.list(), self.notifications)
def is_notification_shown():
    for item in Notifications.list():
        if item['title'] == NOTIFICATION_TITLE:
            return False
    return True
def is_notification_exists(text):
    for item in Notifications.list():
        if item['text'] == text:
            return True
    return False
예제 #7
0
    def get(self):
        from plugins import gateway_led, yeelight

        cursor = get_cursor()
        cursor.execute('SELECT DISTINCT ON (sid) sid, temperature, humidity FROM ht ORDER BY sid, dt DESC')
        sensors_current = []
        sensors_data = {}

        for sid, temperature, humidity in cursor.fetchall():
            sensors_current.append({
                'sid': sid,
                'name': config.SENSORS.get(sid, {}).get('name', sid),
                'temperature': format_value(temperature, split=True),  #'{:0.2f}'.format(temperature/100.0),
                'humidity': format_value(humidity, split=True)  #'{:0.2f}'.format(humidity/100.0)
            })

            sensors_data[sid] = {
                'labels': [],
                'datasets': [
                    {
                        'label': 'Temperature',
                        'data': [],
                        'borderColor': '#bf3d3d'
                    },
                    {
                        'label': 'Humidity',
                        'data': [],
                        'borderColor': '#b7bce5'
                    }
                ]
            }
            cursor.execute('SELECT sid, temperature, humidity, dt FROM ht WHERE sid = %s ORDER BY dt DESC LIMIT 25', (sid,))

            for sid, temperature, humidity, dt in reversed(cursor.fetchall()):
                sensors_data[sid]['labels'].append(dt.isoformat())
                sensors_data[sid]['datasets'][0]['data'].append(format_value(temperature))
                sensors_data[sid]['datasets'][1]['data'].append(format_value(humidity))

        bg_images = map(lambda x: '/static/img/bg/%s' % x, os.listdir(os.path.join(os.path.dirname(__file__), "static", "img", "bg")))
        bg_images = list(filter(lambda x: x.endswith('.jpg'), bg_images))

        brightness, color, status = gateway_led.get_status()
        brightness = int(brightness, 16) / 100

        magnets = []
        for sid, sensor in config.SENSORS.items():
            if sensor.get('device') == 'magnet':
                magnet_status = get_store().get('magnet_{}'.format(sid))
                magnets.append({
                    'sid': sid,
                    'name': sensor.get('name'),
                    'status': magnet_status.decode() if magnet_status else 'open',
                })

        self.render(
            "templates/index.html",
            sensors=config.SENSORS,
            sensors_current=sensors_current,
            sensors_data=sensors_data,
            magnets=magnets,
            bg_images=bg_images,
            gateway_led={
                'brightness': hex(int(brightness*100))[2:],
                'color': color,
                'status': status
            },
            bulbs=yeelight.get_devices(),
            notifications=Notifications.list()
        )