Skip to content

Commit

Permalink
New "last api call successful" & "status" sensors
Browse files Browse the repository at this point in the history
New "last api call successful" & "status" sensors
  • Loading branch information
figorr authored Oct 7, 2024
1 parent 9f4f41b commit c4a15e7
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 13 deletions.
22 changes: 15 additions & 7 deletions custom_components/ecowater_softener/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
DATA_SCHEMA_USER = vol.Schema(
{
vol.Required("username"): str,
vol.Required("password"): str
vol.Required("password"): str,
vol.Required("dateformat"): vol.In(['dd/mm/yyyy', 'mm/dd/yyyy']) # Añadir opción de formato de fecha
}
)

Expand All @@ -30,7 +31,9 @@ async def async_step_user(self, user_input: Optional[Dict[str, Any]] = None):
self.data = user_input

try:
ecowater_account = await self.hass.async_add_executor_job(lambda: ecowater_softener.EcowaterAccount(self.data["username"], self.data["password"]))
ecowater_account = await self.hass.async_add_executor_job(
lambda: ecowater_softener.EcowaterAccount(self.data["username"], self.data["password"])
)
except:
errors["base"] = "login_fail"
return self.async_show_form(
Expand All @@ -39,7 +42,9 @@ async def async_step_user(self, user_input: Optional[Dict[str, Any]] = None):
errors=errors
)

ecowater_devices = await self.hass.async_add_executor_job(lambda: ecowater_account.get_devices())
ecowater_devices = await self.hass.async_add_executor_job(
lambda: ecowater_account.get_devices()
)

existing_entries = self._async_current_entries()
configured_serial_numbers = {entry.data["device_serial_number"] for entry in existing_entries}
Expand All @@ -50,7 +55,6 @@ async def async_step_user(self, user_input: Optional[Dict[str, Any]] = None):
return self.async_abort(reason="no_available_devices")

return await self.async_step_device()


return self.async_show_form(
step_id="user",
Expand All @@ -62,10 +66,14 @@ async def async_step_device(self, user_input: Optional[Dict[str, Any]] = None):
if user_input is not None:
self.data["device_serial_number"] = user_input["device_serial_number"]

return self.async_create_entry(title="Ecowater " + self.data["device_serial_number"], data=self.data)
# Crear entrada de configuración con el formato de fecha seleccionado
return self.async_create_entry(
title="Ecowater " + self.data["device_serial_number"],
data=self.data # Aquí se almacena también el formato de fecha elegido
)

return self.async_show_form(
step_id="device", data_schema= vol.Schema({
step_id="device", data_schema=vol.Schema({
vol.Required("device_serial_number"): vol.In(self.device_list)
})
)
)
4 changes: 3 additions & 1 deletion custom_components/ecowater_softener/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
RECHARGE_ENABLED = "recharge_enabled"
RECHARGE_STATUS = "recharge_status"
ROCK_REMOVED = "rock_removed"
ROCK_REMOVED_DAILY_AVERAGE = "rock_removed_avg_daily"
ROCK_REMOVED_DAILY_AVERAGE = "rock_removed_avg_daily"
LAST_API_CALL_SUCCESSFUL = "last_api_call_successful"
STATUS = "status"
4 changes: 2 additions & 2 deletions custom_components/ecowater_softener/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"documentation": "https://github.com/barleybobs/homeassistant-ecowater-softener/",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/barleybobs/homeassistant-ecowater-softener/issues",
"requirements": ["ecowater-softener==2.1.3"],
"version": "4.0.0"
"requirements": ["ecowater-softener-test==2.2.2"],
"version": "4.2.0"
}
20 changes: 19 additions & 1 deletion custom_components/ecowater_softener/sensor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from dataclasses import dataclass

import logging


from homeassistant.helpers.entity import DeviceInfo
from homeassistant.components.sensor import (
SensorDeviceClass,
Expand Down Expand Up @@ -38,11 +41,15 @@
RECHARGE_ENABLED,
RECHARGE_STATUS,
ROCK_REMOVED,
ROCK_REMOVED_DAILY_AVERAGE
ROCK_REMOVED_DAILY_AVERAGE,
LAST_API_CALL_SUCCESSFUL,
STATUS
)

from .coordinator import EcowaterDataCoordinator

_LOGGER = logging.getLogger(__name__)

@dataclass
class EcowaterSensorEntityDescription(SensorEntityDescription):
"""A class that describes sensor entities"""
Expand Down Expand Up @@ -141,6 +148,17 @@ class EcowaterSensorEntityDescription(SensorEntityDescription):
device_class=SensorDeviceClass.WEIGHT,
state_class=SensorStateClass.TOTAL,
native_unit_of_measurement=UnitOfMass.POUNDS
),
EcowaterSensorEntityDescription(
key=LAST_API_CALL_SUCCESSFUL,
translation_key="last_api_call_successful",
icon="mdi:calendar-clock",
device_class=SensorDeviceClass.TIMESTAMP
),
EcowaterSensorEntityDescription(
key=STATUS,
translation_key="status",
icon="mdi:lan-connect"
)
)

Expand Down
57 changes: 55 additions & 2 deletions custom_components/ecowater_softener/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"user": {
"data": {
"username": "Username",
"password": "Password"
"password": "Password",
"dateformat": "Date Format"
},
"description": "Enter your Ecowater credentials.\nThen pick the date format that your Ecowater device uses.",
"title": "Login"
Expand All @@ -23,5 +24,57 @@
"abort": {
"no_available_devices": "No available devices to configure."
}
},
"entity": {
"sensor": {
"water_available": {
"name": "Water Available"
},
"water_usage_today": {
"name": "Water Used Today"
},
"water_usage_daily_average": {
"name": "Average Water Used per Day"
},
"current_water_flow": {
"name": "Water Flow"
},
"salt_level_percentage": {
"name": "Salt Level Percentage"
},
"out_of_salt_on": {
"name": "Out of Salt On"
},
"days_until_out_of_salt": {
"name": "Days Until Out of Salt"
},
"salt_type": {
"name": "Salt Type"
},
"last_recharge_date": {
"name": "Last Recharge"
},
"days_since_recharge": {
"name": "Days Since Recharge"
},
"recharge_enabled": {
"name": "Recharge Enabled"
},
"recharge_status": {
"name": "Recharge Status"
},
"rock_removed": {
"name": "Rock Removed"
},
"rock_removed_daily_average": {
"name": "Average Rock Removed per Day"
},
"last_api_call_successful": {
"name": "Last Update"
},
"status": {
"name": "Status"
}
}
}
}
}

0 comments on commit c4a15e7

Please sign in to comment.