From c4a15e7ba351c15213d875af7779c9a0a4d55f96 Mon Sep 17 00:00:00 2001 From: figorr <77553975+figorr@users.noreply.github.com> Date: Tue, 8 Oct 2024 00:03:31 +0200 Subject: [PATCH] New "last api call successful" & "status" sensors New "last api call successful" & "status" sensors --- .../ecowater_softener/config_flow.py | 22 ++++--- custom_components/ecowater_softener/const.py | 4 +- .../ecowater_softener/manifest.json | 4 +- custom_components/ecowater_softener/sensor.py | 20 ++++++- .../ecowater_softener/strings.json | 57 ++++++++++++++++++- 5 files changed, 94 insertions(+), 13 deletions(-) diff --git a/custom_components/ecowater_softener/config_flow.py b/custom_components/ecowater_softener/config_flow.py index 54be71e..987f0cf 100644 --- a/custom_components/ecowater_softener/config_flow.py +++ b/custom_components/ecowater_softener/config_flow.py @@ -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 } ) @@ -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( @@ -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} @@ -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", @@ -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) }) - ) \ No newline at end of file + ) diff --git a/custom_components/ecowater_softener/const.py b/custom_components/ecowater_softener/const.py index 18e40fc..40c98f8 100644 --- a/custom_components/ecowater_softener/const.py +++ b/custom_components/ecowater_softener/const.py @@ -15,4 +15,6 @@ RECHARGE_ENABLED = "recharge_enabled" RECHARGE_STATUS = "recharge_status" ROCK_REMOVED = "rock_removed" -ROCK_REMOVED_DAILY_AVERAGE = "rock_removed_avg_daily" \ No newline at end of file +ROCK_REMOVED_DAILY_AVERAGE = "rock_removed_avg_daily" +LAST_API_CALL_SUCCESSFUL = "last_api_call_successful" +STATUS = "status" diff --git a/custom_components/ecowater_softener/manifest.json b/custom_components/ecowater_softener/manifest.json index d9ee56b..5f92b8a 100644 --- a/custom_components/ecowater_softener/manifest.json +++ b/custom_components/ecowater_softener/manifest.json @@ -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" } diff --git a/custom_components/ecowater_softener/sensor.py b/custom_components/ecowater_softener/sensor.py index 6ad1963..ec8aafd 100644 --- a/custom_components/ecowater_softener/sensor.py +++ b/custom_components/ecowater_softener/sensor.py @@ -1,5 +1,8 @@ from dataclasses import dataclass +import logging + + from homeassistant.helpers.entity import DeviceInfo from homeassistant.components.sensor import ( SensorDeviceClass, @@ -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""" @@ -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" ) ) diff --git a/custom_components/ecowater_softener/strings.json b/custom_components/ecowater_softener/strings.json index 2c0c2b0..52dca90 100644 --- a/custom_components/ecowater_softener/strings.json +++ b/custom_components/ecowater_softener/strings.json @@ -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" @@ -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" + } + } } -} \ No newline at end of file +}