-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
52 changed files
with
1,601 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# -*- coding: utf-8 -*- | ||
def color_command(log, args, cfg_i18n): | ||
from domogik.butler.brain import do_command | ||
from domogik.butler.brain import remove_accents | ||
|
||
log.debug("color_command > get i18n informations") | ||
basic_colors = cfg_i18n['BASIC_COLORS'] | ||
colors = cfg_i18n['COLORS'] | ||
DONE = cfg_i18n['DONE'] | ||
UNKNOWN_DEVICE = cfg_i18n['UNKNOWN_DEVICE'] | ||
UNKNOWN_COLOR = cfg_i18n['UNKNOWN_COLOR'] | ||
TXT_BASIC_COLORS_1 = cfg_i18n['TXT_BASIC_COLORS_1'] | ||
TXT_BASIC_COLORS_2 = cfg_i18n['TXT_BASIC_COLORS_2'] | ||
TXT_COLOR_LIST = cfg_i18n['TXT_COLOR_LIST'] | ||
|
||
# put all keys lower case | ||
log.debug("color_command > preprocess color list") | ||
raw_colors = colors | ||
colors.update(basic_colors) | ||
colors = dict((remove_accents(k.lower()), v) for k, v in colors.iteritems()) | ||
|
||
log.debug("color_command > process args") | ||
tab_args = ' '.join(args).split(",") | ||
print(tab_args) | ||
locale = tab_args[0].strip() | ||
dt_type_list = tab_args[1].strip() | ||
device = tab_args[2].strip() | ||
value = tab_args[3].strip() | ||
# optionnal parameter to get informations about a color | ||
if len(tab_args) > 4: | ||
arg4 = tab_args[4].strip() | ||
|
||
log.debug("color_command > do the action") | ||
if value in colors: | ||
value = colors[value] | ||
|
||
elif value == "listcolors": | ||
resp = u"{0}".format(TXT_BASIC_COLORS_1) | ||
for a_color in basic_colors: | ||
resp += u", {0}".format(a_color) | ||
resp += u". {0}".format(TXT_BASIC_COLORS_2) | ||
return resp | ||
|
||
elif value == "detailcolor": | ||
resp = u"{0} {1}".format(TXT_COLOR_LIST, arg4) | ||
search_color = remove_accents(arg4.lower()) | ||
for a_color in raw_colors: | ||
the_color = remove_accents(a_color.lower()) | ||
if search_color in the_color: | ||
resp += u", {0}".format(a_color) | ||
return resp | ||
|
||
else: | ||
return u"{0}".format(UNKNOWN_COLOR) | ||
res = do_command(log, locale, dt_type_list=dt_type_list, device=device, value=value) | ||
if res == None: | ||
return u"{0} : {1}".format(UNKNOWN_DEVICE, device) | ||
else: | ||
return u"{0}".format(DONE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# -*- coding: utf-8 -*- | ||
import subprocess | ||
|
||
def test_internet(log, cfg_i18n): | ||
""" Test ping on interner | ||
1. test a ping on an ip to check if network is ok | ||
2. test a ping on an url to check if DNS is working | ||
""" | ||
ip = "8.8.8.8" # google dns server | ||
log.debug("Ping '{0}'...".format(ip)) | ||
response_ip = ping(log, ip) # Google DNS server | ||
|
||
# ip ping ko | ||
if response_ip != 0: | ||
log.warning("Unable to ping '{0}'".format(ip)) | ||
return cfg_i18n['NO_IP_ACCESS'] | ||
# ip ping ok | ||
else: | ||
log.debug("Ping OK") | ||
dom = "www.free.fr" | ||
log.debug("Ping '{0}'".format(dom)) | ||
response_dns = ping(log, dom) | ||
if response_dns != 0: | ||
log.warning("Unable to ping '{0}'".format(dom)) | ||
return cfg_i18n['NO_DNS_ACCESS'] | ||
else: | ||
log.debug("Ping OK") | ||
return cfg_i18n['OK'] | ||
|
||
def ping(log, remote): | ||
cmd = ["/bin/ping", "-c1", "-w2", remote] | ||
log.debug("Ping command : {0}".format(cmd)) | ||
ping_action = subprocess.Popen(cmd, stdout=subprocess.PIPE) | ||
ping_action.communicate() | ||
return ping_action.returncode | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// DT_Basics is a file for all sensors of : | ||
// - DT_Number | ||
// - DT_String | ||
// - DT_Bool | ||
|
||
|
||
// shortcut | ||
// double ,, because no unit | ||
+ shortcut basic * | ||
- The value is <call>get_sensor_value en_US, DT_Number|DT_String|DT_Bool, , <star></call> | ||
|
||
+ give me the value (of|at) * | ||
@shortcut basic <star2> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
+ shortcut color command * dev * val * | ||
- <call>do_color_command en_US, <star1>, <star2>, <star3></call> | ||
|
||
+ change the color (of|at) * to * | ||
@ shortcut color command DT_ColorRGBHexa dev <star2> val <star3> | ||
|
||
// TODO : complete with questions to ask about the colors. See fr_FR for the example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
// raccourci | ||
// shortcut | ||
+ shortcut humidity * | ||
- The humidity at <star> is <call>get_sensor_value en_US DT_Humidity pourcents <star></call> | ||
- The humidity at <star> is <call>get_sensor_value en_US, DT_Humidity, pourcents, <star></call> | ||
|
||
// phrases | ||
+ what is the humidity (at|of) * | ||
@shortcut humidity <star2> | ||
|
||
+ humidity * | ||
@shortcut humidity <star> | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
/* ##suggest## | ||
? .* execute.* ((?:la |le |l ).*) | ||
@ execute <star1> | ||
*/ | ||
|
||
+ shortcut trigger command * dev * | ||
- <call>do_command fr_FR, <star1>, <star2></call> | ||
|
||
+ (execute) * | ||
@ shortcut trigger command DT_Trigger dev <star2> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
////////////////////////////////////////////////// | ||
// shortcuts | ||
|
||
// TODO. See fr_FR for examples | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.