Skip to content

Commit

Permalink
Add convenience actions:
Browse files Browse the repository at this point in the history
- `get_battery_reserve`
- `get_operating_mode`

> [!WARNING]
> Untested since I'm on the road

Signed-off-by: Stefan Rubner <stefan@whocares.de>
  • Loading branch information
RustyDust committed Dec 31, 2024
1 parent 0d8c4ff commit e22c4da
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
33 changes: 33 additions & 0 deletions custom_components/sonnenbatterie/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,25 @@ async def get_tou_schedule(call: ServiceCall) -> ServiceResponse:
"schedule": response,
}

# noinspection PyUnusedLocal
async def get_battery_reserve(call: ServiceCall) -> ServiceResponse:
sb_conn = _get_sb_connection(call.data)
await sb_conn.login()
response = await sb_conn.sb2.get_battery_reserve()
await sb_conn.logout()
return {
"backup_reserve": response,
}

async def get_operating_mode(call: ServiceCall) -> ServiceResponse:
sb_conn = _get_sb_connection(call.data)
await sb_conn.login()
response = await sb_conn.sb2.get_operating_mode()
await sb_conn.logout()
return {
"operating_mode": response,
}

# service registration
hass.services.async_register(
DOMAIN,
Expand Down Expand Up @@ -262,6 +281,20 @@ async def get_tou_schedule(call: ServiceCall) -> ServiceResponse:
supports_response=SupportsResponse.ONLY,
)

hass.services.async_register(
DOMAIN,
"get_battery_reserve",
get_battery_reserve,
supports_response=SupportsResponse.ONLY,
)

hass.services.async_register(
DOMAIN,
"get_operating_mode",
get_operating_mode,
supports_response=SupportsResponse.ONLY,
)

# Done setting up the entry
return True

Expand Down
14 changes: 14 additions & 0 deletions custom_components/sonnenbatterie/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,17 @@ get_tou_schedule:
selector:
device:
integration: sonnenbatterie
get_battery_reserve:
fields:
device_id:
required: true
selector:
device:
integration: sonnenbatterie
get_operating_mode:
fields:
device_id:
required: true
selector:
device:
integration: sonnenbatterie
22 changes: 22 additions & 0 deletions custom_components/sonnenbatterie/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,28 @@
"example": "1234567890"
}
}
},
"get_battery_reserve": {
"name": "Auslesen der Batterie-Reserve",
"description": "Liefert die von der Sonnebatterie als Reserve zurückgehaltene Kapazität in Prozent",
"fields": {
"device_id": {
"description": "HomeAssistant ID des Geräts",
"name": "Device ID",
"example": "1234567890"
}
}
},
"get_operating_mode": {
"name": "Betriebsmodus auslesen",
"description": "Liefert den aktuellen Betriebsmodus der Sonnebatterie in numerischer Form",
"fields": {
"device_id": {
"description": "HomeAssistant ID des Geräts",
"name": "Device ID",
"example": "1234567890"
}
}
}
}
}
24 changes: 23 additions & 1 deletion custom_components/sonnenbatterie/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,28 @@
"example": "1234567890"
}
}
},
"get_battery_reserve": {
"name": "Get battery reserve",
"description": "Returns the percentage of capacity the Sonnebatterie keeps back.",
"fields": {
"device_id": {
"description": "HomeAssistant ID of the target device",
"name": "Device ID",
"example": "1234567890"
}
}
},
"get_operating_mode": {
"name": "Get operating mode",
"description": "Returns the current operating mode of the SonnenBatterie in numeric form",
"fields": {
"device_id": {
"description": "HomeAssistant ID of the target device",
"name": "Device ID",
"example": "1234567890"
}
}
}
}
}
}

0 comments on commit e22c4da

Please sign in to comment.