Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telegram edit enclosure mesage #871

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions terrariumNotification.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,12 @@ def message(self, message_type, data=None, files=[]):
try:
# Legacy text formatting using '$' sign
text = message.message.replace("${", "{").format(**data)
codelist = re.findall("{.*}", text)
codelist = re.findall("{.*?}",text)

for code in codelist:
result = eval(code[1:-1], {"__builtins__": {}}, {})
text = text.replace(code, result)

result = eval(code[1:-1],{"__builtins__": {}}, {})
text = text.replace(code,result)
except Exception as ex:
logger.error(f"Wrong message formatting {ex}")

Expand Down Expand Up @@ -2599,7 +2599,20 @@ async def area(self, update, context, enclosure_id=None):
message = [f"Enclosure {self.engine.enclosures[enclosure_id].name} current area(s) status:"]

for area in self.engine.enclosures[enclosure_id].areas.values():
message.append(f"- Area {area.name} type {area.type} => {'ON' if area.state['powered'] else 'OFF'} ")
if area.mode == "sensors":
message.append(f"- Area {area.name} type {area.type} => {'ON' if area.state['powered'] else 'OFF'}")
message.append(f"\t\tcurrent: \t{area.state['sensors']['current']:.2f} ({area.state['sensors']['alarm_min']:.2f} - {area.state['sensors']['alarm_max']:.2f})")
elif area.mode == "weather":
message.append(f"- Area {area.name} type {area.type}")
for period in ['day', 'night', 'low', 'high']:
try:
if area.state[period] and area.state[period]['begin']:
message.append(f"\t\t{period}: \t{datetime.datetime.fromtimestamp(area.state[period]['begin']):%H:%M} - {datetime.datetime.fromtimestamp(area.state[period]['end']):%H:%M} ({datetime.datetime.fromtimestamp(area.state[period]['duration']):%H} hours) => {'ON' if area.state[period]['powered'] else 'OFF'}")
except:
pass
else:
message.append(f"- Area {area.name} type {area.type} => {'ON' if area.state['powered'] else 'OFF'}")


await query_message.edit_text("\n".join(message))

Expand Down