Skip to content

Commit

Permalink
#103 TECH: Use get_plugin_config() instead of template sensor TZ in …
Browse files Browse the repository at this point in the history
…package.yaml

 - For HA_NAME and time_zone this in fixed.
  • Loading branch information
ArdJonker committed Oct 2, 2024
1 parent 26df000 commit 72433bc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ The next release might include:
### Added

- #96 FEATURE: Strip leading and trailing whitespace from user input
- Documentation for getting remote access / remote support (#104)

### Fixed

- 🪲 BUG: Timeout on __force_get_register on modbus_evse_client not handled (#98)

### Changed

- None
- 🛠️ FR: Charge mode "Off" now keeps polling the charger and is renamed to Pause (#100)
- TECH: Use get_plugin_config() instead of template sensor TZ in package.yaml (#103


### Removed

Expand All @@ -41,7 +44,7 @@ The next release might include:

### Added

- Documentation for getting remote access / remote support (#104)
- None


### Fixed
Expand All @@ -50,7 +53,7 @@ The next release might include:

### Changed

- 🛠️ FR: Charge mode "Off" now keeps polling the charger and is renamed to Pause (#100)
- None

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# Timezone, untyped here..
TZ = ""

HA_NAME: str = ""

NOTIFICATION_RECIPIENTS: list = []
ADMIN_MOBILE_NAME: str = ""
ADMIN_MOBILE_PLATFORM: str = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,13 @@ class V2GLibertyGlobals(ServiceResponseApp):

async def initialize(self):
self.log("Initializing V2GLibertyGlobals")
# AppDaemon gets it's TZ from appdaemon.yaml. The user has set the right timezone in HA already.
# A separate setting for AppDaemon does not make sense? It is an extra setting with a possibility of mistakes.
# To get the HA timezone into AppDaemon a sensor in HA is created that is read here.
tz = await self.get_state('sensor.time_zone', attribute='state')
c.TZ = pytz.timezone(tz)
config = await self.get_plugin_config()
# Use the HA time_zone, and not the TZ from appdaemon.yaml that AD uses.
c.TZ = pytz.timezone(config['time_zone'])
# For footer of notifications
c.HA_NAME = config['location_name']
# The currency is dictated by the energy provider so it is not retrieved from the config here.
self.log(f"initialize | {c.HA_NAME=}, {c.TZ=}, local_now: {get_local_now()}.")

c.EVENT_RESOLUTION = timedelta(minutes=c.FM_EVENT_RESOLUTION_IN_MINUTES)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class V2Gliberty(hass.Hass):
# CONSTANTS
# TODO: Move to EVSE client?
DISCONNECTED_STATE: int = 0
HA_NAME: str = ""

# Wait time before notifying the user(s) if the car is still connected during a calendar event
MAX_EVENT_WAIT_TO_DISCONNECT: timedelta
Expand Down Expand Up @@ -84,9 +83,6 @@ class V2Gliberty(hass.Hass):
async def initialize(self):
self.log("Initializing V2Gliberty")

self.HA_NAME = await self.get_state("zone.home", attribute="friendly_name")
self.log(f"Name of HA instance: '{self.HA_NAME}'.")

# If this variable is None it means the current SoC is below the max-soc.
self.back_to_max_soc = None

Expand Down Expand Up @@ -214,7 +210,7 @@ def notify_user(self,
if actions:
notification_data['actions'] = actions

message = message + " [" + self.HA_NAME + "]"
message = message + " [" + c.HA_NAME + "]"

self.log(f"Notifying recipients: {to_notify} with message: '{message[0:15]}...' data: {notification_data}.")
for recipient in to_notify:
Expand Down

0 comments on commit 72433bc

Please sign in to comment.