Skip to content

Commit

Permalink
Merge pull request #40 from zestysoft/revert-to-v1.4.6
Browse files Browse the repository at this point in the history
Revert to v1.4.6
  • Loading branch information
zestysoft authored Nov 29, 2024
2 parents 66ff17b + dd187b6 commit 69f8e49
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 65 deletions.
32 changes: 16 additions & 16 deletions custom_components/sensus_analytics/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ async def async_step_user(self, user_input=None) -> FlowResult:
vol.Required(CONF_ACCOUNT_NUMBER): str,
vol.Required(CONF_METER_NUMBER): str,
vol.Required("unit_type", default="CF"): vol.In(["CF", "G"]),
vol.Optional("tier1_gallons", default=None): vol.Any(None, vol.Coerce(float), vol.Range(min=0)),
vol.Required("tier1_gallons", default=7480.52): cv.positive_float,
vol.Required("tier1_price", default=0.0128): cv.positive_float,
vol.Optional("tier2_gallons", default=None): vol.Any(None, vol.Coerce(float), vol.Range(min=0)),
vol.Optional("tier2_price", default=None): vol.Any(None, vol.Coerce(float), vol.Range(min=0)),
vol.Optional("tier3_price", default=None): vol.Any(None, vol.Coerce(float), vol.Range(min=0)),
vol.Required("tier2_gallons", default=7480.52): cv.positive_float,
vol.Required("tier2_price", default=0.0153): cv.positive_float,
vol.Required("tier3_price", default=0.0202): cv.positive_float,
vol.Required("service_fee", default=15.00): cv.positive_float,
}
)
Expand Down Expand Up @@ -126,26 +126,26 @@ async def async_step_init(self, user_input=None) -> FlowResult:
default=self.config_entry.data.get(CONF_METER_NUMBER),
): str,
vol.Required("unit_type", default=self.config_entry.data.get("unit_type", "CF")): vol.In(["CF", "G"]),
vol.Optional(
vol.Required(
"tier1_gallons",
default=self.config_entry.data.get("tier1_gallons", None),
): vol.Any(None, vol.Coerce(float), vol.Range(min=0)),
default=self.config_entry.data.get("tier1_gallons", 7480.52),
): cv.positive_float,
vol.Required(
"tier1_price",
default=self.config_entry.data.get("tier1_price", 0.0128),
): cv.positive_float,
vol.Optional(
vol.Required(
"tier2_gallons",
default=self.config_entry.data.get("tier2_gallons", None),
): vol.Any(None, vol.Coerce(float), vol.Range(min=0)),
vol.Optional(
default=self.config_entry.data.get("tier2_gallons", 7480.52),
): cv.positive_float,
vol.Required(
"tier2_price",
default=self.config_entry.data.get("tier2_price", None),
): vol.Any(None, vol.Coerce(float), vol.Range(min=0)),
vol.Optional(
default=self.config_entry.data.get("tier2_price", 0.0153),
): cv.positive_float,
vol.Required(
"tier3_price",
default=self.config_entry.data.get("tier3_price", None),
): vol.Any(None, vol.Coerce(float), vol.Range(min=0)),
default=self.config_entry.data.get("tier3_price", 0.0202),
): cv.positive_float,
vol.Required(
"service_fee",
default=self.config_entry.data.get("service_fee", 15.00),
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.4.7",
"version": "1.4.6",
"documentation": "https://github.com/zestysoft/sensus_analytics_integration",
"dependencies": [],
"codeowners": ["@zestysoft"],
Expand Down
72 changes: 24 additions & 48 deletions custom_components/sensus_analytics/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,36 +274,24 @@ def native_value(self):

def _calculate_cost(self, usage_gallons):
"""Calculate the billing cost based on tiers and service fee."""
tier1_gallons = self.coordinator.config_entry.data.get("tier1_gallons") or 0
tier1_gallons = self.coordinator.config_entry.data.get("tier1_gallons")
tier1_price = self.coordinator.config_entry.data.get("tier1_price")
tier2_gallons = self.coordinator.config_entry.data.get("tier2_gallons") or 0
tier2_price = self.coordinator.config_entry.data.get("tier2_price") or 0
tier3_price = self.coordinator.config_entry.data.get("tier3_price") or 0
tier2_gallons = self.coordinator.config_entry.data.get("tier2_gallons")
tier2_price = self.coordinator.config_entry.data.get("tier2_price")
tier3_price = self.coordinator.config_entry.data.get("tier3_price")
service_fee = self.coordinator.config_entry.data.get("service_fee")

cost = service_fee
if usage_gallons is not None:
if tier1_gallons == 0:
# No tier 1 limit, all usage is charged at tier 1 price
if usage_gallons <= tier1_gallons:
cost += usage_gallons * tier1_price
elif tier2_gallons == 0:
# No tier 2 limit, calculate for tier 1 and tier 2
if usage_gallons <= tier1_gallons:
cost += usage_gallons * tier1_price
else:
cost += tier1_gallons * tier1_price
cost += (usage_gallons - tier1_gallons) * tier2_price
elif tier3_price > 0:
# Calculate for all three tiers
if usage_gallons <= tier1_gallons:
cost += usage_gallons * tier1_price
elif usage_gallons <= tier1_gallons + tier2_gallons:
cost += tier1_gallons * tier1_price
cost += (usage_gallons - tier1_gallons) * tier2_price
else:
cost += tier1_gallons * tier1_price
cost += tier2_gallons * tier2_price
cost += (usage_gallons - tier1_gallons - tier2_gallons) * tier3_price
elif usage_gallons <= tier1_gallons + tier2_gallons:
cost += tier1_gallons * tier1_price
cost += (usage_gallons - tier1_gallons) * tier2_price
else:
cost += tier1_gallons * tier1_price
cost += tier2_gallons * tier2_price
cost += (usage_gallons - tier1_gallons - tier2_gallons) * tier3_price

return round(cost, 2)

Expand All @@ -329,34 +317,22 @@ def native_value(self):

def _calculate_daily_fee(self, usage_gallons):
"""Calculate the daily fee based on tiers."""
tier1_gallons = self.coordinator.config_entry.data.get("tier1_gallons") or 0
tier1_gallons = self.coordinator.config_entry.data.get("tier1_gallons")
tier1_price = self.coordinator.config_entry.data.get("tier1_price")
tier2_gallons = self.coordinator.config_entry.data.get("tier2_gallons") or 0
tier2_price = self.coordinator.config_entry.data.get("tier2_price") or 0
tier3_price = self.coordinator.config_entry.data.get("tier3_price") or 0
tier2_gallons = self.coordinator.config_entry.data.get("tier2_gallons")
tier2_price = self.coordinator.config_entry.data.get("tier2_price")
tier3_price = self.coordinator.config_entry.data.get("tier3_price")

cost = 0
if usage_gallons is not None:
if tier1_gallons == 0:
# No tier 1 limit, all usage is charged at tier 1 price
if usage_gallons <= tier1_gallons:
cost += usage_gallons * tier1_price
elif tier2_gallons == 0:
# No tier 2 limit, calculate for tier 1 and tier 2
if usage_gallons <= tier1_gallons:
cost += usage_gallons * tier1_price
else:
cost += tier1_gallons * tier1_price
cost += (usage_gallons - tier1_gallons) * tier2_price
elif tier3_price > 0:
# Calculate for all three tiers
if usage_gallons <= tier1_gallons:
cost += usage_gallons * tier1_price
elif usage_gallons <= tier1_gallons + tier2_gallons:
cost += tier1_gallons * tier1_price
cost += (usage_gallons - tier1_gallons) * tier2_price
else:
cost += tier1_gallons * tier1_price
cost += tier2_gallons * tier2_price
cost += (usage_gallons - tier1_gallons - tier2_gallons) * tier3_price
elif usage_gallons <= tier1_gallons + tier2_gallons:
cost += tier1_gallons * tier1_price
cost += (usage_gallons - tier1_gallons) * tier2_price
else:
cost += tier1_gallons * tier1_price
cost += tier2_gallons * tier2_price
cost += (usage_gallons - tier1_gallons - tier2_gallons) * tier3_price

return round(cost, 2)

0 comments on commit 69f8e49

Please sign in to comment.