-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #364 from nathanmarlor/feature/charge-period-card
Add support for the charge period card
- Loading branch information
Showing
8 changed files
with
122 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from typing import Any | ||
|
||
import voluptuous as vol | ||
from homeassistant.components import websocket_api | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.core import callback | ||
from homeassistant.helpers import config_validation as cv | ||
|
||
from ..const import DOMAIN | ||
from ..const import FRIENDLY_NAME | ||
from ..const import INVERTERS | ||
from .utils import get_controller_from_friendly_name_or_device_id | ||
|
||
|
||
def register(hass: HomeAssistant) -> None: | ||
hass.components.websocket_api.async_register_command(get_charge_periods) | ||
|
||
|
||
@websocket_api.websocket_command( | ||
{ | ||
vol.Required("type"): "foxess_modbus/get_charge_periods", | ||
vol.Required("inverter"): vol.Any(cv.string, None), | ||
} | ||
) | ||
@callback | ||
def get_charge_periods(hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg: dict[str, Any]) -> None: | ||
inverter_controllers = [x for entry in hass.data[DOMAIN].values() for x in entry[INVERTERS]] | ||
controller = get_controller_from_friendly_name_or_device_id(msg["inverter"], inverter_controllers, hass) | ||
charge_periods = [] | ||
for charge_period in controller.charge_periods: | ||
charge_periods.append( | ||
{ | ||
"period_start_entity_id": charge_period.period_start_entity_id, | ||
"period_end_entity_id": charge_period.period_end_entity_id, | ||
"enable_force_charge_entity_id": charge_period.enable_force_charge_entity_id, | ||
"enable_charge_from_grid_entity_id": charge_period.enable_charge_from_grid_entity_id, | ||
} | ||
) | ||
connection.send_result( | ||
msg["id"], | ||
{ | ||
"friendly_name": controller.inverter_details[FRIENDLY_NAME], | ||
"charge_periods": charge_periods, | ||
}, | ||
) |