-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set field in config flow to same value as global powercalc configurat…
…ion (#1870) * Set field in config flow to same value as global powercalc configuration * Fix tests * Fix for library flow * Implement service for changing gui configuration * Add documentation * Remove return
- Loading branch information
1 parent
e076f7b
commit 3584079
Showing
10 changed files
with
314 additions
and
61 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
Empty file.
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 @@ | ||
import homeassistant.helpers.config_validation as cv | ||
import voluptuous as vol | ||
from homeassistant.core import HomeAssistant, ServiceCall | ||
from homeassistant.exceptions import HomeAssistantError | ||
from homeassistant.loader import bind_hass | ||
|
||
from custom_components.powercalc import ( | ||
CONF_CREATE_UTILITY_METERS, | ||
CONF_ENERGY_INTEGRATION_METHOD, | ||
CONF_IGNORE_UNAVAILABLE_STATE, | ||
DOMAIN, | ||
ENERGY_INTEGRATION_METHODS, | ||
) | ||
from custom_components.powercalc.const import CONF_CREATE_ENERGY_SENSOR | ||
|
||
ALLOWED_CONFIG_KEYS = [ | ||
CONF_CREATE_ENERGY_SENSOR, | ||
CONF_CREATE_UTILITY_METERS, | ||
CONF_IGNORE_UNAVAILABLE_STATE, | ||
CONF_ENERGY_INTEGRATION_METHOD, | ||
] | ||
|
||
SERVICE_SCHEMA = vol.Schema({ | ||
vol.Required("field"): vol.In(ALLOWED_CONFIG_KEYS), | ||
vol.Required("value"): cv.string, | ||
}) | ||
|
||
|
||
@bind_hass | ||
def change_gui_configuration(hass: HomeAssistant, call: ServiceCall) -> None: | ||
field = call.data["field"] | ||
value = call.data["value"] | ||
|
||
if field in [CONF_CREATE_ENERGY_SENSOR, CONF_CREATE_UTILITY_METERS, CONF_IGNORE_UNAVAILABLE_STATE]: | ||
value = cv.boolean(value) | ||
|
||
if field == CONF_ENERGY_INTEGRATION_METHOD and value not in ENERGY_INTEGRATION_METHODS: | ||
raise HomeAssistantError(f"Invalid integration method {value}") | ||
|
||
for entry in hass.config_entries.async_entries(DOMAIN): | ||
if field not in entry.data: | ||
continue | ||
new_data = entry.data.copy() | ||
new_data[field] = value | ||
hass.config_entries.async_update_entry(entry, data=new_data) |
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
Empty file.
Oops, something went wrong.