Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
fritz-smh committed Dec 20, 2016
2 parents e344724 + 30792ec commit 22890b6
Show file tree
Hide file tree
Showing 52 changed files with 1,601 additions and 95 deletions.
18 changes: 18 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@
Changelog
=========

1.4
===

* Small improvment on @donneMoi in begin.rive (fr_FR)
* Add network test (fr_FR)
* Add user management feature for the 'name' information (fr_FR)
* Upgrades to do commands and get sensors : add the ability to use the command or sensor reference (used)

1.3
===

* Big internal upgrades to had more capabilities to commands and sensors management.
* Add DT_ColorRGBHexa management.
* Complete DT_Bool and childs management.
* Add management of basic sensors : DT_Number, DT_Bool, DT_String.
* Various minor improvments.
* en_US and nl_NL features are not as complete as fr_FR. See the 'TODO' tags in the .rive files for more informations.

1.2
===

Expand Down
2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"domogik_min_version": "0.5.0",
"name": "base",
"type": "brain",
"version": "1.2"
"version": "1.4"
},
"json_version": 2
}
59 changes: 59 additions & 0 deletions lib/color_command.py
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)
36 changes: 36 additions & 0 deletions lib/network.py
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

15 changes: 15 additions & 0 deletions rs/en_US/DT_Basic_sensors.rive
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>


6 changes: 5 additions & 1 deletion rs/en_US/DT_Bool.rive
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
+ shortcut bool command * dev * val *
- <call>trigger_bool_command en_US__SEP__<star1>__SEP__<star2>__SEP__<star3></call>
- <call>do_command en_US, <star1>, <star2>, <star3></call>

+ switch * on
@shortcut bool command DT_Switch dev <star> val 1
Expand All @@ -12,3 +12,7 @@

+ disable *
@shortcut bool command DT_Enable dev <star> val 0


// TODO : get the status of switches and open/close sensors
// See fr_FR for the example
8 changes: 8 additions & 0 deletions rs/en_US/DT_ColorRGBHexa.rive
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
7 changes: 2 additions & 5 deletions rs/en_US/DT_Humidity.rive
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>



4 changes: 2 additions & 2 deletions rs/en_US/DT_Temp.rive
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// raccourci
// shortcut
+ shortcut temperature *
- The temperature at <star> is <call>get_sensor_value en_US DT_Temp degres <star></call>
- The temperature at <star> is <call>get_sensor_value en_US, DT_Temp, degres, <star></call>

+ what is the temperature (at|of) *
@shortcut temperature <star2>
Expand Down
12 changes: 12 additions & 0 deletions rs/en_US/DT_Trigger.rive
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>

5 changes: 5 additions & 0 deletions rs/en_US/begin.rive
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//////////////////////////////////////////////////
// shortcuts

// TODO. See fr_FR for examples

14 changes: 10 additions & 4 deletions rs/en_US/datetime.rive
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@

import locale
import time
import traceback
from domogik.common.utils import ucode
now = time.localtime(time.time())
try:
locale.setlocale(locale.LC_ALL, LOCALE)
locale.setlocale(locale.LC_ALL, str(LOCALE))
except:
rs.log.error(u"Error : {0}".format(traceback.format_exc()))
return ERROR_LOCALE
return time.strftime(DISPLAY_FORMAT, now)
return ucode(time.strftime(DISPLAY_FORMAT, now))
< object

> object get_date python
Expand All @@ -24,12 +27,15 @@

import locale
import time
import traceback
from domogik.common.utils import ucode
now = time.localtime(time.time())
try:
locale.setlocale(locale.LC_ALL, LOCALE)
locale.setlocale(locale.LC_ALL, str(LOCALE))
except:
rs.log.error(u"Error : {0}".format(traceback.format_exc()))
return ERROR_LOCALE
return time.strftime(DISPLAY_FORMAT, now)
return ucode(time.strftime(DISPLAY_FORMAT, now))
< object


Expand Down
Loading

0 comments on commit 22890b6

Please sign in to comment.