Skip to content

Commit 942b215

Browse files
authored
Merge pull request #34 from zestysoft/fix-config-exception
Improve configuration experience
2 parents 1751e6f + 2a26d49 commit 942b215

File tree

3 files changed

+100
-16
lines changed

3 files changed

+100
-16
lines changed

custom_components/sensus_analytics/config_flow.py

+35-14
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def is_matching(self, other_flow):
2727
return False # Return False if you don't have specific matching logic
2828

2929
async def async_step_user(self, user_input=None) -> FlowResult:
30-
"""Handle the initial step."""
30+
"""Handle the initial step of the config flow."""
3131
errors = {}
3232

3333
if user_input is not None:
@@ -100,55 +100,76 @@ async def async_step_init(self, user_input=None) -> FlowResult:
100100
if user_input is not None:
101101
_LOGGER.debug("User updated options: %s", user_input)
102102
# Update the entry with new options
103-
self.hass.config_entries.async_update_entry(self.config_entry, data=user_input)
103+
self.hass.config_entries.async_update_entry(self.config_entry, options=user_input)
104104
return self.async_create_entry(title="", data={})
105105

106106
data_schema = vol.Schema(
107107
{
108108
vol.Required(
109109
CONF_BASE_URL,
110-
default=self.config_entry.data.get(CONF_BASE_URL),
110+
default=self.config_entry.options.get(CONF_BASE_URL, self.config_entry.data.get(CONF_BASE_URL)),
111111
): str,
112112
vol.Required(
113113
CONF_USERNAME,
114-
default=self.config_entry.data.get(CONF_USERNAME),
114+
default=self.config_entry.options.get(CONF_USERNAME, self.config_entry.data.get(CONF_USERNAME)),
115115
): str,
116116
vol.Required(
117117
CONF_PASSWORD,
118-
default=self.config_entry.data.get(CONF_PASSWORD),
118+
default=self.config_entry.options.get(CONF_PASSWORD, self.config_entry.data.get(CONF_PASSWORD)),
119119
): str,
120120
vol.Required(
121121
CONF_ACCOUNT_NUMBER,
122-
default=self.config_entry.data.get(CONF_ACCOUNT_NUMBER),
122+
default=self.config_entry.options.get(
123+
CONF_ACCOUNT_NUMBER,
124+
self.config_entry.data.get(CONF_ACCOUNT_NUMBER),
125+
),
123126
): str,
124127
vol.Required(
125128
CONF_METER_NUMBER,
126-
default=self.config_entry.data.get(CONF_METER_NUMBER),
129+
default=self.config_entry.options.get(
130+
CONF_METER_NUMBER,
131+
self.config_entry.data.get(CONF_METER_NUMBER),
132+
),
127133
): str,
128-
vol.Required("unit_type", default=self.config_entry.data.get("unit_type", "CF")): vol.In(["CF", "G"]),
134+
vol.Required(
135+
"unit_type",
136+
default=self.config_entry.options.get("unit_type", self.config_entry.data.get("unit_type", "CF")),
137+
): vol.In(["CF", "G"]),
129138
vol.Optional(
130139
"tier1_gallons",
131-
default=self.config_entry.data.get("tier1_gallons", None),
140+
default=self.config_entry.options.get(
141+
"tier1_gallons", self.config_entry.data.get("tier1_gallons", None)
142+
),
132143
): vol.Any(None, vol.Coerce(float), vol.Range(min=0)),
133144
vol.Required(
134145
"tier1_price",
135-
default=self.config_entry.data.get("tier1_price", 0.0128),
146+
default=self.config_entry.options.get(
147+
"tier1_price", self.config_entry.data.get("tier1_price", 0.0128)
148+
),
136149
): cv.positive_float,
137150
vol.Optional(
138151
"tier2_gallons",
139-
default=self.config_entry.data.get("tier2_gallons", None),
152+
default=self.config_entry.options.get(
153+
"tier2_gallons", self.config_entry.data.get("tier2_gallons", None)
154+
),
140155
): vol.Any(None, vol.Coerce(float), vol.Range(min=0)),
141156
vol.Optional(
142157
"tier2_price",
143-
default=self.config_entry.data.get("tier2_price", None),
158+
default=self.config_entry.options.get(
159+
"tier2_price", self.config_entry.data.get("tier2_price", None)
160+
),
144161
): vol.Any(None, vol.Coerce(float), vol.Range(min=0)),
145162
vol.Optional(
146163
"tier3_price",
147-
default=self.config_entry.data.get("tier3_price", None),
164+
default=self.config_entry.options.get(
165+
"tier3_price", self.config_entry.data.get("tier3_price", None)
166+
),
148167
): vol.Any(None, vol.Coerce(float), vol.Range(min=0)),
149168
vol.Required(
150169
"service_fee",
151-
default=self.config_entry.data.get("service_fee", 15.00),
170+
default=self.config_entry.options.get(
171+
"service_fee", self.config_entry.data.get("service_fee", 15.00)
172+
),
152173
): cv.positive_float,
153174
}
154175
)

custom_components/sensus_analytics/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"domain": "sensus_analytics",
33
"name": "Sensus Analytics Integration",
4-
"version": "1.4.7",
4+
"version": "1.5.0",
55
"documentation": "https://github.com/zestysoft/sensus_analytics_integration",
66
"dependencies": [],
77
"codeowners": ["@zestysoft"],

custom_components/sensus_analytics/translations/en.json

+64-1
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,80 @@
66
"title": "Configure Sensus Analytics",
77
"data": {
88
"base_url": "Base URL",
9+
"base_url_description": "Enter the base URL for the Sensus Analytics API (e.g., https://api.sensus.com).",
10+
911
"username": "Username",
12+
"username_description": "Enter your Sensus Analytics username.",
13+
1014
"password": "Password",
15+
"password_description": "Enter your Sensus Analytics password.",
16+
1117
"account_number": "Account Number",
18+
"account_number_description": "Enter your Sensus Analytics account number.",
19+
1220
"meter_number": "Meter Number",
21+
"meter_number_description": "Enter your Sensus Analytics meter number.",
22+
1323
"unit_type": "Unit Type (CF or G)",
24+
"unit_type_description": "Select the unit type. 'CF' stands for Cubic Feet and 'G' stands for Gallons.",
25+
1426
"tier1_gallons": "Tier 1 Gallons",
27+
"tier1_gallons_description": "Enter the number of gallons for Tier 1. Leave blank if not applicable.",
28+
1529
"tier1_price": "Tier 1 Price",
30+
"tier1_price_description": "Enter the price per gallon for Tier 1 (e.g., 0.0128).",
31+
1632
"tier2_gallons": "Tier 2 Gallons",
33+
"tier2_gallons_description": "Enter the number of gallons for Tier 2. Leave blank if not applicable.",
34+
1735
"tier2_price": "Tier 2 Price",
36+
"tier2_price_description": "Enter the price per gallon for Tier 2 (e.g., 0.0150).",
37+
1838
"tier3_price": "Tier 3 Price",
19-
"service_fee": "Service Fee"
39+
"tier3_price_description": "Enter the price per gallon for Tier 3 (e.g., 0.0175).",
40+
41+
"service_fee": "Service Fee",
42+
"service_fee_description": "Enter the fixed service fee amount (e.g., 15.00)."
43+
}
44+
},
45+
"init": {
46+
"title": "Configure Sensus Analytics Options",
47+
"data": {
48+
"base_url": "Base URL",
49+
"base_url_description": "Enter the base URL for the Sensus Analytics API (e.g., https://api.sensus.com).",
50+
51+
"username": "Username",
52+
"username_description": "Enter your Sensus Analytics username.",
53+
54+
"password": "Password",
55+
"password_description": "Enter your Sensus Analytics password.",
56+
57+
"account_number": "Account Number",
58+
"account_number_description": "Enter your Sensus Analytics account number.",
59+
60+
"meter_number": "Meter Number",
61+
"meter_number_description": "Enter your Sensus Analytics meter number.",
62+
63+
"unit_type": "Unit Type (CF or G)",
64+
"unit_type_description": "Select the unit type. 'CF' stands for Cubic Feet and 'G' stands for Gallons.",
65+
66+
"tier1_gallons": "Tier 1 Gallons",
67+
"tier1_gallons_description": "Enter the number of gallons for Tier 1. Leave blank if not applicable.",
68+
69+
"tier1_price": "Tier 1 Price",
70+
"tier1_price_description": "Enter the price per gallon for Tier 1 (e.g., 0.0128).",
71+
72+
"tier2_gallons": "Tier 2 Gallons",
73+
"tier2_gallons_description": "Enter the number of gallons for Tier 2. Leave blank if not applicable.",
74+
75+
"tier2_price": "Tier 2 Price",
76+
"tier2_price_description": "Enter the price per gallon for Tier 2 (e.g., 0.0150).",
77+
78+
"tier3_price": "Tier 3 Price",
79+
"tier3_price_description": "Enter the price per gallon for Tier 3 (e.g., 0.0175).",
80+
81+
"service_fee": "Service Fee",
82+
"service_fee_description": "Enter the fixed service fee amount (e.g., 15.00)."
2083
}
2184
}
2285
},

0 commit comments

Comments
 (0)