Crewski/njsPC-HA

KeyError: 'saltLevel' while setting up njspc_ha platform for sensor

a1k0n opened this issue · 2 comments

a1k0n commented

I also get a hitch on initial setup...

2022-09-13 15:23:59.969 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up njspc_ha platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 281, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/njspc_ha/sensor.py", line 45, in async_setup_entry
    new_devices.append(SaltSensor(coordinator, chlorinator))
  File "/config/custom_components/njspc_ha/sensor.py", line 312, in __init__
    self._value = chlorinator["saltLevel"]
KeyError: 'saltLevel'

This is what I get from the chlorinator status:

pi@pool:~/nodejs-poolController $ curl -s http://localhost:4200/state/chlorinator/1|jq .
{
  "id": 1,
  "disabled": false,
  "isActive": true,
  "spaSetpoint": 3,
  "poolSetpoint": 60,
  "body": {
    "val": 32,
    "name": "poolspa",
    "desc": "Pool/Spa"
  },
  "name": "Intellichlor--40",
  "type": {
    "val": 0,
    "name": "pentair",
    "desc": "Pentair"
  },
  "status": {
    "val": 128,
    "name": "commlost",
    "desc": "Communication Lost"
  },
  "superChlorHours": 8,
  "superChlor": false,
  "superChlorRemaining": 0,
  "targetOutput": 60,
  "lastComm": 28800000,
  "currentOutput": 0,
  "model": {
    "val": 3,
    "name": "intellichlor--40",
    "desc": "IntelliChlor IC40",
    "capacity": 40000,
    "chlorinePerDay": 1.4,
    "chlorinePerSec": 1.6203703703703704e-05
  },
  "equipmentType": "chlorinator",
  "saltTarget": 3400
}

My chlorinator cell is currently off (short circuiting and popping breakers), need to get that looked at; but the upshot is status is "commlost" and I have no saltLevel though I do have a currentOutput.

maybe not a big deal? the plugin seems to recover despite throwing the exception.

Looks like I need to do some error checking for the sensors. I'll see about defaulting to 0 if the key isn't available. That way once its fixed, it'll start populating the value. The other way is to check on setup, but then a reboot of HA would be needed to capture the sensor again.

This should be resolved with the latest release.