Skip to content

Commit

Permalink
Merge pull request #45 from jumping2000/beta
Browse files Browse the repository at this point in the history
Beta --> Master 25/4/2023
  • Loading branch information
jumping2000 authored Apr 25, 2023
2 parents 77bf0d7 + 8e56523 commit 9735cb9
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 19 deletions.
3 changes: 2 additions & 1 deletion apps/notifier/alexa_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,8 @@ def worker(self):

time.sleep(duration)
self.volume_restore()

########
self.set_state(self.debug_sensor, state="OK")
except UnboundLocalError as ex:
self.lg(f"VOLUMES AUTO SILENT: {ex}")
pass
Expand Down
6 changes: 4 additions & 2 deletions apps/notifier/gh_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
SUB_TTS = [("[\*\-\[\]_\(\)\{\~\|\}\s]+"," ")]
SUB_VOICE = [
# ("[.]{2,}", "."),
("[\U00010000-\U0010ffff]", ""), # strip emoji
("[\?\.\!,]+(?=[\?\.\!,])", ""), # Exclude duplicate
("(\s+\.|\s+\.\s+|[\.])(?! )(?![^{]*})(?![^\d.]*\d)", ". "),
("&", " and "), # escape
Expand Down Expand Up @@ -121,7 +122,7 @@ def speak(self, google, gh_mode: bool, gh_notifier: str):
self.volume_get(gh_volume,float(self.get_state(self.args["tts_period_of_day_volume"]))/100)
self.mediastate_get(gh_volume,float(self.get_state(self.args["tts_period_of_day_volume"]))/100)
wait_time = float(self.get_state(self.gh_wait_time))
message = h.replace_regular(google["message"], SUB_TTS)
message = h.replace_regular(google["message"], SUB_VOICE)
### set volume
self.volume_set(gh_player,google["volume"])
# queues the message to be handled async, use when_tts_done_do method to supply callback when tts is done
Expand Down Expand Up @@ -162,7 +163,7 @@ def worker(self):
time.sleep(1)
#self.volume_set(entity,data["volume"])
##### Speech time calculator #####
message_clean = h.replace_regular(data["text"], SUB_VOICE)
message_clean = data["text"]
words = len(h.remove_tags(message_clean).split())
chars = h.remove_tags(message_clean).count("")
duration = (words * 0.007) * 60
Expand All @@ -187,6 +188,7 @@ def worker(self):
if self.ytube_called:
self.call_service("media_player/volume_set", entity_id = entity, volume_level = 0)
##################################
self.set_state(self.debug_sensor, state="OK")
except Exception as ex:
self.log("An error occurred in GH Manager - Errore nel Worker: {}".format(ex),level="ERROR")
self.log(sys.exc_info())
Expand Down
2 changes: 2 additions & 0 deletions apps/notifier/gh_manager.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
GH_Manager:
module: gh_manager
class: GH_Manager

#log_level: DEBUG

gh_service: tts.google
ytube_player: media_player.ytube_music_player
Expand Down
18 changes: 12 additions & 6 deletions apps/notifier/helpermodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,19 @@ def return_array(target)->list:
else:
return list(target.split(","))

def replace_regular(text, substitutions: list)->str:
if isinstance(text, str):
for old,new in substitutions:
text = re.sub(old, new, text.strip())
# def replace_regular(text, substitutions: list)->str:
# if isinstance(text, str):
# for old,new in substitutions:
# text = re.sub(old, new, text.strip())
# return text
# else:
# return text

def replace_regular(text: str, substitutions: list) -> str:
for old, new in substitutions:
regex = re.compile(old)
text = re.sub(regex, new, str(text).strip())
return text
else:
return text

def replace_language(s: str)->str:
return (s[:2])
Expand Down
4 changes: 2 additions & 2 deletions apps/notifier/notification_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def send_notify(self, data, notify_name, assistant_name: str):
extra_data = {}
if isinstance(telegram, dict):
extra_data = telegram
if link !="":
messaggio = ("{} {}".format(messaggio,link))
if caption == "":
caption = ("{}\n{}".format(titolo,messaggio))
if image != "" and image.find("http") != -1:
Expand All @@ -103,8 +105,6 @@ def send_notify(self, data, notify_name, assistant_name: str):
#self.log("[EXTRA-DATA]: {}".format(extra_data), ascii_encode = False)
if str(html).lower() not in ["true","on","yes","1"]:
messaggio = messaggio.replace("_","\_")
if link !="":
messaggio = ("{} {}".format(messaggio,link))
if image != "":
self.call_service(item, message = "", data = extra_data)
elif extra_data:
Expand Down
17 changes: 9 additions & 8 deletions apps/notifier/notifier_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ def notifier(self, event_name, data, kwargs):
if data["html"] == "":
data.update({"html": self.get_state(self.html_mode)})
###########################
self.set_state(self.debug_sensor, state="OK")
###########################
if usePersistentNotification:
try:
self.notification_manager.send_persistent(data, self.persistent_notification_info)
Expand All @@ -183,6 +185,13 @@ def notifier(self, event_name, data, kwargs):
self.log("An error occurred in text notification: {}".format(ex), level="ERROR")
self.set_debug_sensor("Error in Text Notification: ", ex)
self.log(sys.exc_info())
if usePhone:
try:
self.phone_manager.send_voice_call(data, phone_notify_name, self.phone_sip_server)
except Exception as ex:
self.log("An error occurred in phone notification: {}".format(ex),level="ERROR")
self.set_debug_sensor("Error in Phone Notification: ", ex)
self.log(sys.exc_info())
if useTTS:
if (gh_switch == "on" or google_priority_flag) and google_flag:
if (data["google"]) != "":
Expand All @@ -200,14 +209,6 @@ def notifier(self, event_name, data, kwargs):
if "title" not in alexa:
alexa["title"] = data["title"]
self.alexa_manager.speak(alexa, self.alexa_skill_id)
if usePhone:
try:
self.phone_manager.send_voice_call(data, phone_notify_name, self.phone_sip_server)
except Exception as ex:
self.log("An error occurred in phone notification: {}".format(ex),level="ERROR")
self.set_debug_sensor("Error in Phone Notification: ", ex)
self.log(sys.exc_info())

### ripristino del priority a OFF
if (self.get_state(self.priority_message) == "on"):
self.set_state(self.priority_message, state = "off")

0 comments on commit 9735cb9

Please sign in to comment.