Skip to content

Commit

Permalink
Merge pull request #68 from DerOetzi/homeassistant-auto-discovery
Browse files Browse the repository at this point in the history
Stabilized InfluxDB host settings for missing scheme configuration
  • Loading branch information
DerOetzi authored Apr 20, 2024
2 parents f4ade77 + cbd0c9f commit 729d63d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ SE2MQTT_MQTT__USERNAME=
# Set your Wallbox serial number
#SE2MQTT_WALLBOX__SERIAL=

# Save power values to InfluxDB set your host
# Save power values to InfluxDB set your host (e.g. http://localhost)
#SE2MQTT_INFLUXDB__HOST=

# Save power values to InfluxDB set your port (default 8086)
Expand Down
4 changes: 2 additions & 2 deletions solaredge2mqtt/service/influxdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, settings: InfluxDBSettings, prices: PriceSettings) -> None:
self.prices: PriceSettings = prices

self.client: InfluxDBClient = InfluxDBClient(
url=f"{settings.host}:{settings.port}",
url=settings.url,
token=settings.token.get_secret_value(),
org=settings.org,
)
Expand Down Expand Up @@ -151,7 +151,7 @@ async def query_dataframe(

async def init_client_async(self) -> None:
self.client_async = InfluxDBClientAsync(
url=f"{self.settings.host}:{self.settings.port}",
url=self.settings.url,
token=self.settings.token.get_secret_value(),
org=self.settings.org,
)
Expand Down
8 changes: 8 additions & 0 deletions solaredge2mqtt/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ class InfluxDBSettings(BaseModel):
retention: int = Field(SECONDS_PER_2_YEARS)
retention_raw: int = Field(25)

@property
def url(self) -> str:
url = f"{self.host}:{self.port}"
if not str(self.host).startswith(("http://", "https://")):
url = f"http://{url}"

return url

@property
def is_configured(self) -> bool:
return all(
Expand Down

0 comments on commit 729d63d

Please sign in to comment.