homeassistant-ecowater-softener
homeassistant-ecowater-softener copied to clipboard
"Status" sensor and "Last API call Successful" sensor
In the previous code there was a "status" sensor that was showing if the device was "online" or "offline"
At ecowater.py there was this part of code:
def getData(self):
try:
data = self._get()
new_data = {}
nextRecharge_re = "device-info-nextRecharge'\)\.html\('(?P<nextRecharge>.*)'"
new_data['daysUntilOutOfSalt'] = int(data['out_of_salt_days'])
new_data['outOfSaltOn'] = data['out_of_salt']
new_data['saltLevel'] = data['salt_level']
new_data['saltLevelPercent'] = data['salt_level_percent']
new_data['waterUsageToday'] = data['water_today']
new_data['waterUsageDailyAverage'] = data['water_avg']
new_data['waterAvailable'] = data['water_avail']
new_data['waterFlow'] = data['water_flow']
new_data['waterUnits'] = data['water_units']
new_data['rechargeEnabled'] = data['rechargeEnabled']
new_data['rechargeScheduled'] = False if (re.search(nextRecharge_re, data['recharge'])).group('nextRecharge') == 'Not Scheduled' else True
new_data['deviceStatus'] = data['online']
return new_data
except Exception as e:
logging.error(f'Error with data: {e}')
return ''
Was the API sending the data for the status sensor? I don't know if it could be easily implemented in the new code? Or maybe it could be added in another way.
Then the integration, at sensor.py was adding the status sensor:
SENSOR_TYPES: tuple[EcowaterSensorEntityDescription, ...] = (
EcowaterSensorEntityDescription(
key=STATUS,
name="status",
icon="mdi:power",
),
It is a sensor I was using to manage an automation that sends a notification when the device became "offline". It is not a huge problem ... I can modify the automation just to check if any other sensor (like "water used today") became "unavailable" or "unknown".
Thank you for all the work. The integration looks great.