Added Switchbot web plugin

This commit is contained in:
Fabio Manganiello 2018-05-08 17:07:01 +02:00
parent 598c917eda
commit d75326bbe8
4 changed files with 81 additions and 1 deletions

View File

@ -0,0 +1,29 @@
#switchbot-container {
background-color: #f8f8f8;
padding: 12px;
border: 1px solid #ddd;
border-radius: 10px;
font-family: "Raleway", "HelveticaNeue", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 400;
line-height: 38px;
letter-spacing: .1rem;
}
.switchbot-device {
padding: 1.5em 1em .2em .5em;
border-radius: 10px;
}
.switchbot-device:nth-of-type(odd) {
background-color: #ececec;
}
.switchbot-device:hover {
background-color: #daf8e2 !important;
}
.toggle-container {
text-align: right;
padding-right: 1em;
}

View File

@ -0,0 +1,33 @@
$(document).ready(function() {
var switches,
$switchbotContainer = $('#switchbot-container');
var initBindings = function() {
$switchbotContainer.on('click touch', '.switch-ctrl-container', function() {
var $input = $(this).find('.switch-ctrl');
var addr = $input.attr('name');
$input.prop('checked', true);
execute(
{
type: 'request',
action: 'switch.switchbot.press',
args: {
device: addr
}
},
onSuccess = function(response) {
$input.prop('checked', false);
}
);
});
};
var init = function() {
initBindings();
};
init();
});

View File

@ -0,0 +1,17 @@
<script type="text/javascript" src="{{ url_for('static', filename='js/switch.switchbot.js') }}"></script>
<link rel="stylesheet" href="{{ url_for('static', filename='css/switch.switchbot.css') }}"></script>
<div id="switchbot-container" class="row">
{% for addr, name in configuration['devices'].items() %}
<div class="row switchbot-device" data-addr="{{ addr }}">
<div class="ten columns name">{{ name }}</div>
<div class="two columns toggle-container">
<div class="toggle toggle--push switch-ctrl-container">
<label for="{{ addr }}" class="toggle--btn"></label>
<input type="checkbox" name="{{ addr }}" class="toggle--checkbox switch-ctrl">
</div>
</div>
</div>
{% endfor %}
</div>

View File

@ -89,10 +89,11 @@ class SwitchSwitchbotPlugin(SwitchPlugin):
"""
def __init__(self, bt_interface=None, connect_timeout=None,
scan_timeout=None, *args, **kwargs):
scan_timeout=None, devices={}, *args, **kwargs):
self.bt_interface = bt_interface
self.connect_timeout = connect_timeout if connect_timeout else 5
self.scan_timeout = scan_timeout if scan_timeout else 2
self.devices = devices
def _run(self, device, command=None):