Skip to content

Commit 2ac65ed

Browse files
authored
Merge pull request #48 from kaulketh/develop
Develop
2 parents 2525bd6 + a18b789 commit 2ac65ed

File tree

7 files changed

+50
-38
lines changed

7 files changed

+50
-38
lines changed

bot/conf/greenhouse_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
language settings
1414
import required lib
1515
set index in global library
16-
"""
16+
"""
1717
if language_index == 0:
1818
import conf.lib_english as lib
1919
elif language_index == 1:

bot/conf/lib_global.py

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
file_log_greenhouse = '/greenhouse.log'
3333
file_log_debug = '/greenhouse_console.log'
3434
file_log_update = '/update_bot.log'
35+
latest_release = '/greenhouseLatestRelease.id'
3536
commit_id = '/greenhouseRepoCommit.id'
3637
cloned_branch = '/greenhouseRepoBranch.name'
3738
bot_dir = '/home/pi/scripts/TelegramBot/'

bot/greenhouse.py

+8-17
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def __start(bot, update):
106106
return SELECTION
107107

108108

109-
""" set the target, member of group or group """
109+
# set the target, member of group or group
110110
def __selection(bot, update):
111111
global target
112112
target = update.message.text
@@ -140,7 +140,7 @@ def __selection(bot, update):
140140
return DURATION
141141

142142

143-
""" set water duration """
143+
# set water duration
144144
def __duration(bot, update):
145145
global water_time
146146
global g_duration_update
@@ -236,7 +236,7 @@ def __duration(bot, update):
236236
return SELECTION
237237

238238

239-
""" watering targets """
239+
# watering targets
240240
def __all_off():
241241
logging.info('Switch all off.')
242242
for channel in all_groups:
@@ -308,9 +308,7 @@ def __water_group(bot, update, group):
308308
return
309309

310310

311-
"""
312-
get humidity and temperature values
313-
"""
311+
# get humidity and temperature values
314312
def __message_values(update):
315313
""" to avoid refresh intervals shorter than 3 seconds """
316314
time.sleep(3)
@@ -345,10 +343,8 @@ def __stop(bot, update):
345343
display.show_standby()
346344
return ConversationHandler.END
347345

348-
349-
"""
350-
[#39] Implement emergency stop
351-
"""
346+
347+
# [#39] Implement emergency stop
352348
@run_async
353349
def __emergency_stop_handler(bot, update, chat_data):
354350
emergency = update.message.text
@@ -366,10 +362,7 @@ def __start_emergency_stop(bot, update):
366362
return
367363

368364

369-
"""
370-
[#30] implement standby
371-
init after given time without user activity
372-
"""
365+
# [#30] implement standby init after given time without user activity
373366
def __start_standby_timer(bot, update):
374367
global timer_job
375368
timer_job = jq.run_once(__job_stop_and_restart, conf.standby_timeout, context=update)
@@ -383,9 +376,7 @@ def __stop_standby_timer(bot, upadate):
383376
return
384377

385378

386-
"""
387-
job to stop and restart application
388-
"""
379+
# job to stop and restart application
389380
def __job_stop_and_restart(bot, job):
390381
logging.warning("Job: Stop and restart called!")
391382
stop_and_restart.stop_and_restart(job.context)

bot/peripherals/four_digit/four_digits.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import logger.logger as log
2020
logger = log.get_logger()
2121

22-
""" http://www.uize.com/examples/seven-segment-display.html """
22+
# http://www.uize.com/examples/seven-segment-display.html
2323
# 0 1 2 3 4 5 6 7 8 9
2424
hex_digits = [0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f,
2525
# A b C d E F G H h I
@@ -39,8 +39,7 @@
3939

4040

4141
class TM1637:
42-
logger.info('Init pin settings for 4-digit-display!')
43-
global IO
42+
logger.info('Init pin settings four digits display!')
4443
IO = utils.set_pins()
4544
__double_point = False
4645
__clk_pin = 0

bot/peripherals/oled/display.py

+33-15
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@
55
author: Thomas Kaulke, [email protected]
66
"""
77

8+
# TODO: improve and fix imports, load vars from global lib!!!
9+
# from __future__ import absolute_import
10+
# import conf.lib_global as lib
811
import subprocess
912
from time import sleep
1013
from PIL import Image, ImageFont, ImageDraw
11-
from lib_oled96 import Ssd1306
1214
from smbus import SMBus
13-
from ...conf.lib_global import commit_id, cloned_branch, bot_dir
15+
from lib_oled96 import Ssd1306
16+
17+
18+
latest_release = '/greenhouseLatestRelease.id'
19+
commit_id = '/greenhouseRepoCommit.id'
20+
cloned_branch = '/greenhouseRepoBranch.name'
21+
bot_dir = '/home/pi/scripts/TelegramBot/'
1422

1523

1624
# Display setup, methods and members
@@ -24,10 +32,20 @@
2432
switch_time = 15
2533

2634

27-
def get_last_commit():
28-
commit = None
29-
branch = None
35+
def __get_release():
36+
try:
37+
release = open(str(latest_release)).read()
38+
if release is None:
39+
release = '-----'
40+
else:
41+
release = release
42+
except Exception:
43+
release = '-----'
44+
return release
45+
return release
46+
3047

48+
def __get_last_commit():
3149
try:
3250
commit = open(str(commit_id)).read()
3351
if commit is None:
@@ -47,7 +65,7 @@ def get_last_commit():
4765
return build
4866

4967

50-
def get_core_temp():
68+
def __get_core_temp():
5169
temp = int(open('/sys/class/thermal/thermal_zone0/temp').read())
5270
one = str(temp).__getitem__(0)
5371
two = str(temp).__getitem__(1)
@@ -60,23 +78,23 @@ def get_core_temp():
6078
font2 = ImageFont.truetype(str(bot_dir) + 'peripherals/oled/fonts/FreeSans.ttf', 12)
6179

6280

63-
def animate(time):
81+
def __animate(time):
6482
# Display clear
6583
oled.cls()
6684
oled.display()
6785
# header
68-
draw.text((18, top), "GREENHOUSE", font=font, fill=1)
86+
draw.text((left, top), "GREENHOUSE v" + __get_release(), font=font, fill=1)
6987
# build
70-
draw.text((left, top + 18), "Build: " + get_last_commit(), font=font2, fill=1)
88+
draw.text((left, top + 18), "Build: " + __get_last_commit(), font=font2, fill=1)
7189
# line
7290
draw.line((left, top + 35, oled.width - left + 128, top + 35), fill=1)
7391
# core temp
74-
draw.text((left, top + 45), "Core Temperature: " + get_core_temp(), font=font2, fill=1)
92+
draw.text((left, top + 45), "Core Temperature: " + __get_core_temp(), font=font2, fill=1)
7593
oled.display()
7694
sleep(time)
7795

7896

79-
def show_pi(time):
97+
def __show_pi(time):
8098
oled.cls()
8199
# image inverted
82100
draw.rectangle((32, top - 3, 95, 63), outline=1, fill=1)
@@ -85,7 +103,7 @@ def show_pi(time):
85103
sleep(time)
86104

87105

88-
def show_state(time):
106+
def __show_state(time):
89107
oled.cls()
90108
oled.display()
91109
"""
@@ -116,9 +134,9 @@ def show_state(time):
116134
while True:
117135

118136
try:
119-
animate(switch_time)
120-
show_pi(3)
121-
show_state(switch_time)
137+
__animate(switch_time)
138+
__show_pi(3)
139+
__show_state(switch_time)
122140

123141
except KeyboardInterrupt:
124142
print('Oled interrupted.')

bot/peripherals/oled/lib_oled96.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
minor adaptions: Thomas Kaulke, [email protected]
2525
"""
2626

27-
from __future__ import absolute_import
2827
from PIL import Image, ImageDraw
2928

3029

@@ -103,7 +102,7 @@ def display(self):
103102
buf.append(byte)
104103
i -= 1
105104

106-
self._data(buf) # push out the whole lot
105+
self._data(buf) # push out the whole lot
107106

108107
def cls(self):
109108
self.canvas.rectangle((0, 0, self.width-1, self.height-1), outline=0, fill=0)

bot/update_bot.sh

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ log='/update_bot.log'
1414
commit_id='/greenhouseRepoCommit.id'
1515
cloned_branch='/greenhouseRepoBranch.name'
1616
bot_dir='/home/pi/scripts/TelegramBot/'
17+
latest_release='/greenhouseLatestRelease.id'
1718
wait=3
1819

1920
# function display usage
@@ -47,6 +48,9 @@ fi
4748
commit=$(curl -s https://api.github.com/repos/${owner}/${project}/commits/${branch} --insecure | grep -Po '(?<="sha":)(.*?)(?=,)' -m 1 | sed "s/\"//g" | sed -e 's/^[[:space:]]*//' | sed -e 's/[.]*$//')
4849
# get saved commit
4950
last_commit=$(cat ${commit_id})
51+
#get latest release
52+
release=$(curl -s https://api.github.com/repos/${owner}/${project}/releases/latest --insecure| grep -Po '"tag_name": "\K.*?(?=")')
53+
echo ${release} > ${latest_release}
5054

5155

5256
# all output to log file

0 commit comments

Comments
 (0)