Skip to content

Commit

Permalink
Merge pull request #51 from zestysoft/use_CCF_or_gal_for_units-2
Browse files Browse the repository at this point in the history
Fix config issue and refresh sensors on config change
  • Loading branch information
zestysoft authored Jan 21, 2025
2 parents b87f8f3 + a399d03 commit 6a8ddc3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions custom_components/sensus_analytics/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ async def async_step_init(self, user_input=None) -> FlowResult:
_LOGGER.debug("User updated options: %s", user_input)
# Update the entry with new options
self.hass.config_entries.async_update_entry(self.config_entry, data=user_input)
# Force a sensor refresh
coordinator = self.hass.data[DOMAIN][self.config_entry.entry_id]
await coordinator.async_request_refresh()
return self.async_create_entry(title="", data={})

# Fetch current configuration data
Expand Down
2 changes: 1 addition & 1 deletion custom_components/sensus_analytics/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "sensus_analytics",
"name": "Sensus Analytics Integration",
"version": "1.6.8",
"version": "1.6.9",
"documentation": "https://github.com/zestysoft/sensus_analytics_integration",
"dependencies": [],
"codeowners": ["@zestysoft"],
Expand Down
6 changes: 3 additions & 3 deletions custom_components/sensus_analytics/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def _convert_usage(self, usage, usage_unit=None):
return None
if usage_unit is None:
usage_unit = self.coordinator.data.get("usageUnit")
if usage_unit == "CF" and self.coordinator.config_entry.data.get("unit_type") == "G":
if usage_unit == "CCF" and self.coordinator.config_entry.data.get("unit_type") == "gal":
try:
return round(float(usage) * CF_TO_GALLON)
except (ValueError, TypeError):
Expand All @@ -75,8 +75,8 @@ def __init__(self, coordinator, entry):
def _get_usage_unit(self):
"""Determine the unit of measurement for usage sensors."""
usage_unit = self.coordinator.data.get("usageUnit")
if usage_unit == "CF" and self.coordinator.config_entry.data.get("unit_type") == "G":
return "G"
if usage_unit == "CCF" and self.coordinator.config_entry.data.get("unit_type") == "gal":
return "gal"
return usage_unit

@property
Expand Down

0 comments on commit 6a8ddc3

Please sign in to comment.