Skip to content

Commit

Permalink
Add live magnet status updates to the webpage; change format of SENSO…
Browse files Browse the repository at this point in the history
…RS config variable
  • Loading branch information
aluminiumgeek committed Aug 23, 2017
1 parent a6ea49e commit 5b25091
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 8 deletions.
10 changes: 5 additions & 5 deletions config.py.example
Expand Up @@ -13,12 +13,12 @@ REDIS_DB = 0
# MiHome App -> Gateway -> Settings -> About -> [Second last menu item]
MIHOME_GATEWAY_PASSWORD = ''

# Sensors - SID : Human-readable name
# Sensors - SID : {device: Device type, name: Human-readable name}
SENSORS = {
'158d000116a58e': 'Office',
'158d0001264ac3': 'Bedroom 1',
'158d0001264ac3': 'Bedroom 2',
'158d00010850da': 'Outside'
'158d000116a58e': {'device': 'sensor_ht', 'name': 'Office'},
'158d0001264ac3': {'device': 'sensor_ht', 'name': 'Bedroom 1'},
'158d0001264ac3': {'device': 'sensor_ht', 'name': 'Outside'},
'158d00010850da': {'device': 'magnet', 'name': 'Balcony door'}
}

ENABLED_APPS = ['random_led_color_every_10_seconds',]
Expand Down
16 changes: 15 additions & 1 deletion web/static/css/main.css
Expand Up @@ -110,7 +110,7 @@ body {
opacity: .7;
}

.yee .wrapper {
.yee .wrapper, .magnet-block {
background-color: rgba(255, 255, 255, 0.5);
border-radius: 4px;
padding: 5px 10px;
Expand Down Expand Up @@ -179,3 +179,17 @@ body {
.yee .slider-selection {
background-image: linear-gradient(to bottom, #c9c9c9 0, #c5c5c5 100%);
}

.magnet-block {
margin: 10px;
display: inline-block;
}

.magnet-block .magnet-name, .magnet-block .magnet-status {
font-size: 16px;
display: inline;
}

.magnet-block .magnet-status {
margin-left: 10px;
}
7 changes: 7 additions & 0 deletions web/static/js/main.js
Expand Up @@ -93,6 +93,13 @@
create_chart(data.sid);
}

if (data.device == 'magnet') {
var magnet = $('.magnet#' + data.sid);
magnet.find('.magnet-name').text(data.name);
var icon = data.status == 'open' ? 'unlock' : 'lock';
magnet.find('.magnet-status').html('<i class="fa fa-' + icon + '"></i>');
}

if (data.device == 'gateway_led') {
if (data.return == 'ok') {
blocked_led_toggle = false;
Expand Down
10 changes: 10 additions & 0 deletions web/templates/index.html
Expand Up @@ -16,6 +16,16 @@
<span class="glyphicon glyphicon-lamp" aria-hidden="true"></span>
<input type='text' id='color' />
</div>
{% if magnets %}
<div class='magnet-block'>
{% for magnet in magnets %}
<div class='magnet' id='{{ magnet["sid"] }}'>
<div class='magnet-name'>{{ magnet['name'] }}</div>
<div class='magnet-status'><i class='fa fa-{{ "lock" if magnet["status"] == "close" else "unlock" }}'></i></div>
</div>
{% end %}
</div>
{% end %}
<div class='container'>
<div class='row ht'>
{% for sensor in sensors_current %}
Expand Down
15 changes: 13 additions & 2 deletions web/w.py
Expand Up @@ -10,7 +10,7 @@

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import config
from utils import format_value, Notifications
from utils import get_store, format_value, Notifications

conn = psycopg2.connect("dbname={} user={} password={}".format(config.DBNAME, config.DBUSER, config.DBPASS))

Expand All @@ -33,7 +33,7 @@ def get(self):
for sid, temperature, humidity in cursor.fetchall():
sensors_current.append({
'sid': sid,
'name': config.SENSORS.get(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)
})
Expand Down Expand Up @@ -66,11 +66,22 @@ def get(self):
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:],
Expand Down

0 comments on commit 5b25091

Please sign in to comment.