File tree Expand file tree Collapse file tree 3 files changed +11
-6
lines changed Expand file tree Collapse file tree 3 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ pip install -r requirements.txt
2525Rename the ` script_config.example.yaml ` file to ` script_config.yaml ` and edit it to suit your needs. All the following keys are mandatory:
2626
2727- ` ha_url ` : URL of your Home Assistant instance
28+ - ` ha_use_ssl ` : Specify if Home Assistant uses SSL or not
2829- ` ha_access_token ` : Long-lived access token for your Home Assistant instance
2930- ` med_cache_db_path ` : Path to the cache database of MyElectricalData
3031- ` med_config_path ` : Path to the configuration file of MyElectricalData
@@ -51,7 +52,7 @@ shell_command:
5152 statistics_delete_all : python statistics_importer/statistics_importer.py -d
5253` ` `
5354
54- You can then create an automation to call the service ` shell_command.statistics_import` periodically or when MyElectricalData cache is updated.
55+ You can then create an automation calling the service ` shell_command.statistics_import` periodically or when MyElectricalData cache is updated.
5556
5657# # Warning
5758- Home Assistant may take some time to display the newly created statistics. Please wait, they will eventually show up in the UI.
Original file line number Diff line number Diff line change 33# URL of Home Assistant
44ha_url : " localhost:8123"
55
6+ # Specify if Home Assistant uses SSL or not
7+ ha_use_ssl : false
8+
69# Long-Lived access token from Home Assistant
710ha_access_token : " xxxxxx"
811
Original file line number Diff line number Diff line change 1- __version__ = '1 .0.0'
1+ __version__ = '2 .0.0'
22
33import aiohttp
44import argparse
@@ -33,6 +33,7 @@ class Config:
3333 ha_access_token : str
3434 med_cache_db_path : str
3535 med_config_path : str
36+ ha_use_ssl : bool = False
3637
3738 @classmethod
3839 def load (cls , path : str = os .path .abspath ("script_config.yaml" )) -> "Config" :
@@ -423,15 +424,15 @@ async def main(args: argparse.Namespace) -> int:
423424 start_time = time .time ()
424425
425426 try :
426- # Read config .yaml
427+ # Read script_config .yaml
427428 config = Config .load ()
428429
429430 # Read MyElectricalData config.yaml
430431 with open (os .path .abspath (config .med_config_path )) as file :
431432 med_config = yaml .safe_load (file )
432433
433434 # Create the WebSocket connection
434- url = f"ws ://{ config .ha_url } /api/websocket"
435+ url = f"{ 'wss' if config . ha_use_ssl else 'ws' } ://{ config .ha_url } /api/websocket"
435436 print ("Connecting to websocket at" , url )
436437
437438 async with aiohttp .ClientSession () as session :
@@ -451,8 +452,8 @@ async def main(args: argparse.Namespace) -> int:
451452
452453 except Exception as e :
453454 tb = traceback .extract_tb (e .__traceback__ )
454- print (f"ERROR on line { tb [0 ].lineno } : { tb [0 ].line } " )
455- print (f"{ type (e ).__name__ } - { e } " )
455+ print (f"ERROR on line { tb [0 ].lineno } : { tb [0 ].line } " , file = sys . stderr )
456+ print (f"{ type (e ).__name__ } - { e } " , file = sys . stderr )
456457 return 1
457458
458459 finally :
You can’t perform that action at this time.
0 commit comments