Skip to content

Commit

Permalink
Merge pull request #41 from caiosweet/beta
Browse files Browse the repository at this point in the history
Beta sync dev 15/11
  • Loading branch information
jumping2000 authored Feb 26, 2023
2 parents e8b6fdb + a7dd8a0 commit d722310
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 122 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

.DS_Store
187 changes: 124 additions & 63 deletions apps/notifier/alexa_manager.py

Large diffs are not rendered by default.

32 changes: 17 additions & 15 deletions apps/notifier/alexa_manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,30 @@ Alexa_Manager:
module: alexa_manager
class: Alexa_Manager

# log_level: DEBUG
log_level: DEBUG

# Alexa hub
bool_smart_volume_set: input_boolean.alexa_smart_volume_set
select_player: input_select.notification_media_player_alexa
sensor_player: sensor.media_player_alexa
select_type: input_select.default_alexa_type
select_method: input_select.default_alexa_method
select_voice: input_select.alexa_voice
bool_ssml: input_boolean.alexa_ssml
binary_speak: binary_sensor.notifier_alexa_speak
bool_smart_volume_set: input_boolean.notifier_alexa_smart_volume
sensor_player: sensor.notifier_player_alexa
select_player: select.notifier_player_alexa
select_type: input_select.notifier_alexa_type
select_method: input_select.notifier_alexa_method
select_voice: input_select.notifier_alexa_voice
select_alexa_language: input_select.notifier_alexa_language
bool_ssml: input_boolean.notifier_alexa_ssml
prosody:
rate: input_number.alexa_prosody_rate
pitch: input_number.alexa_prosody_pitch
volume: input_number.alexa_prosody_volume
rate: input_number.notifier_alexa_prosody_rate
pitch: input_number.notifier_alexa_prosody_pitch
volume: input_number.notifier_alexa_prosody_volume

# Main hub
number_wait_time: input_number.tts_wait_time
select_language: input_select.language
sensor_day_volume: sensor.period_of_day_volume
number_wait_time: input_number.notifier_tts_wait_time
select_language: input_select.notifier_language
sensor_day_volume: sensor.notifier_day_period_volume

# Optional https://github.com/keatontaylor/alexa-actions
actionable_notification: input_text.alexa_actionable_notification

# Debug Sensor Generated by appdaemon
debug_sensor: sensor.centro_notifiche
debug_sensor: sensor.notifier_debug_error
1 change: 0 additions & 1 deletion apps/notifier/gh_manager.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import hassapi as hass
import time
import datetime
import sys
from queue import Queue
from threading import Thread
Expand Down
12 changes: 6 additions & 6 deletions apps/notifier/gh_manager.yaml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ GH_Manager:
ytube_player: media_player.ytube_music_player

# Main hub
gh_wait_time: input_number.tts_wait_time
gh_select_media_player: input_select.notification_media_player_google
gh_sensor_media_player: sensor.media_player_google
tts_period_of_day_volume: sensor.period_of_day_volume
tts_language: input_select.language
gh_wait_time: input_number.notifier_tts_wait_time
gh_select_media_player: select.notifier_player_google
gh_sensor_media_player: sensor.notifier_player_google
tts_period_of_day_volume: sensor.notifier_day_period_volume
tts_language: input_select.notifier_language

# Debug Sensor
debug_sensor: sensor.centro_notifiche
debug_sensor: sensor.notifier_debug_error
Empty file modified apps/notifier/helpermodule.py
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions apps/notifier/notification_manager.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def send_notify(self, data, notify_name, assistant_name: str):
pushover = data["pushover"] if "pushover" in data else ""
mobile = data["mobile"] if "mobile" in data else ""
discord = data["discord"] if "discord" in data else ""
whatsapp_addon = data["whatsapp"] if "whatsapp" in data else ""
whatsapp_addon = data["whatsapp"] if "whatsapp" in data else ""
notify_vector = self.check_notifier(h.return_array(h.replace_regular(data["notify"], SUB_REMOVE_SPACE)),self.split_device_list(str(notify_name)))
#self.log("[NOTIFY_VECTOR]: {}".format(notify_vector), ascii_encode = False)
## target ##
Expand Down Expand Up @@ -137,7 +137,7 @@ def send_notify(self, data, notify_name, assistant_name: str):
{"text": messaggio }
})
#self.log("[EXTRA-DATA_ELSE]: {}".format(extra_data), ascii_encode = False)
self.call_service("whatsapp/send_message", **extra_data)
self.call_service("whatsapp/send_message", **extra_data)
#### WHATSAPP #######################
elif item.find("whatsapp") != -1:
messaggio, titolo = self.prepare_text(html, message, title, timestamp, assistant_name)
Expand Down
6 changes: 3 additions & 3 deletions apps/notifier/notification_manager.yaml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ Notification_Manager:
module: notification_manager
class: Notification_Manager

text_last_message: input_text.last_message
boolean_wrap_text: input_boolean.wrap_text
boolean_tts_clock: input_boolean.tts_clock
text_last_message: input_text.notifier_last_message
boolean_wrap_text: input_boolean.notifier_wrap_text
boolean_tts_clock: input_boolean.notifier_tts_clock
21 changes: 11 additions & 10 deletions apps/notifier/notifier_dispatch.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import hassapi as hass
import sys
import yaml

import hassapi as hass
import helpermodule as h
import yaml

#
# Centralizes messaging.
#
Expand Down Expand Up @@ -42,23 +44,23 @@ def initialize(self):
config = self.get_plugin_config()
config_dir = config["config_dir"]
self.log(f"configuration dir: {config_dir}")
secretsFile = config_dir + "/packages/secrets.yaml"
secretsFile = config_dir + "/secrets.yaml"
with open(secretsFile, "r") as ymlfile:
cfg = yaml.load(ymlfile, Loader=yaml.FullLoader) # yaml.safe_load
self.gh_tts = cfg.get("tts_google", "google_translate_say")
self.gh_notify = cfg.get("notify_google", "google_assistant")
self.phone_sip_server = cfg.get("sip_server_name", "fritz.box:5060")
self.gh_tts_cloud = cfg.get("tts_google_cloud", "google_cloud")
self.reverso_tts = cfg.get("reverso_tts", "reversotts_say")
self.alexa_skill_id = cfg.get("notifyhub_alexa_actionable_skill_id", "")
self.alexa_skill_id = cfg.get("notifier_alexa_actionable_skill_id", "")

### APP MANAGER ###
self.notification_manager = self.get_app("Notification_Manager")
self.gh_manager = self.get_app("GH_Manager")
self.alexa_manager = self.get_app("Alexa_Manager")
self.phone_manager = self.get_app("Phone_Manager")
### LISTEN EVENT ###
self.listen_event(self.notify_hub, "hub")
self.listen_event(self.notifier, "notifier")

#####################################################################
def set_debug_sensor(self, state, error):
Expand Down Expand Up @@ -89,7 +91,7 @@ def createTTSdict(self,data) -> list:
flag = True
return [flag,dizionario]

def notify_hub(self, event_name, data, kwargs):
def notifier(self, event_name, data, kwargs):
self.log("#### START NOTIFIER_DISPATCH ####")
location_status = self.get_state(self.location_tracker)
### FLAG
Expand All @@ -101,15 +103,15 @@ def notify_hub(self, event_name, data, kwargs):
google_flag = self.createTTSdict(data["google"])[0] if len(str(data["google"])) != 0 else False
google = self.createTTSdict(data["google"])[1] if len(str(data["google"])) != 0 else False
google_priority_flag = False
if google_flag :
if google_flag:
if "priority" in google:
if str(google.get("priority")).lower() in ["true","on","yes","1"]:
google_priority_flag = True
### ALEXA ####
alexa_flag = self.createTTSdict(data["alexa"])[0] if len(str(data["alexa"])) != 0 else False
alexa = self.createTTSdict(data["alexa"])[1] if len(str(data["alexa"])) != 0 else False
alexa_priority_flag = False
if alexa_flag :
if alexa_flag:
if "priority" in alexa:
if str(alexa.get("priority")).lower() in ["true","on","yes","1"]:
alexa_priority_flag = True
Expand Down Expand Up @@ -200,8 +202,7 @@ def notify_hub(self, event_name, data, kwargs):
self.alexa_manager.speak(alexa, self.alexa_skill_id)
if usePhone:
try:
language = self.get_state(self.tts_language)
self.phone_manager.send_voice_call(data, phone_notify_name, self.phone_sip_server, language)
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)
Expand Down
34 changes: 17 additions & 17 deletions apps/notifier/notifier_dispatch.yaml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@ Notifier_Dispatch:
module: notifier_dispatch
class: Notifier_Dispatch

gh_tts_google_mode: input_select.tts_notify
gh_switch: input_boolean.google_switch
gh_tts_google_mode: input_select.notifier_tts_notify
gh_switch: input_boolean.notifier_google_switch

alexa_switch: input_boolean.alexa_switch
alexa_switch: input_boolean.notifier_alexa_switch

text_notifications: input_boolean.text_notifications
screen_notifications: input_boolean.screen_notifications
speech_notifications: input_boolean.speech_notifications
phone_notifications: input_boolean.phone_notifications
text_notifications: input_boolean.notifier_text_notifications
screen_notifications: input_boolean.notifier_screen_notifications
speech_notifications: input_boolean.notifier_speech_notifications
phone_notifications: input_boolean.notifier_phone_notifications

html_mode: input_boolean.html_mode
html_mode: input_boolean.notifier_html_mode

persistent_notification_info: persistent_notification.info_messages

location_tracker: group.location_tracker
text_notify: input_select.text_notify
phone_notify: input_select.phone_notify
priority_message: input_boolean.priority_message
guest_mode: input_boolean.guest_mode
dnd: binary_sensor.dnd
location_tracker: group.notifier_location_tracker
text_notify: input_select.notifier_text_notify
phone_notify: input_select.notifier_phone_notify
priority_message: input_boolean.notifier_priority_message
guest_mode: input_boolean.notifier_guest_mode
dnd: binary_sensor.notifier_dnd

personal_assistant_name: input_text.personal_assistant_name
phone_called_number: input_text.phone_called_number
personal_assistant_name: input_text.notifier_personal_assistant
phone_called_number: input_text.notifier_called_number

debug_sensor: sensor.centro_notifiche
debug_sensor: sensor.notifier_debug_error

dependencies:
- Notification_Manager
Expand Down
12 changes: 8 additions & 4 deletions apps/notifier/phone_manager.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import hassapi as hass
import datetime

import hassapi as hass

#
import helpermodule as h

Expand All @@ -12,6 +14,7 @@

class Phone_Manager(hass.Hass):
def initialize(self):
self.tts_language = self.args.get("tts_language")
self.dict_lingua = {
"it-IT": "it-IT-Standard-A",
"en-GB": "en-GB-Standard-A",
Expand All @@ -21,11 +24,11 @@ def initialize(self):
"es-ES": "es-ES-Standard-A",
}

def send_voice_call(self, data, phone_name: str, sip_server_name: str, language: str):
message = self.replace_regular(data["message"], SUB_TTS)
def send_voice_call(self, data, phone_name: str, sip_server_name: str):
message = h.replace_regular(data["message"], SUB_TTS)
message_tts = message.replace(" ", "%20")
called_number = data["called_number"]
language = self.get_state(self.tts_language)
lang = self.dict_lingua.get(self.get_state(self.tts_language))
phone_name = phone_name.lower().replace(" ", "_")
if phone_name.find("voip_call") != -1:
if called_number != "":
Expand All @@ -41,3 +44,4 @@ def send_voice_call(self, data, phone_name: str, sip_server_name: str, language:
called_number, message_tts, lang
)
self.call_service("shell_command/telegram_call", url=url_tts)

2 changes: 1 addition & 1 deletion apps/notifier/phone_manager.yaml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Phone_Manager:
module: phone_manager
class: Phone_Manager

tts_language: input_select.language
tts_language: input_select.notifier_language

0 comments on commit d722310

Please sign in to comment.