Skip to content

Commit

Permalink
I think this does the unregistered correctly... checking..
Browse files Browse the repository at this point in the history
  • Loading branch information
garbled1 committed Nov 12, 2020
1 parent 8989112 commit e6ac54f
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions custom_components/ecowitt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_TIMESTAMP,
)

from homeassistant.components.binary_sensor import (
DEVICE_CLASS_MOISTURE,
)

Expand Down Expand Up @@ -597,37 +600,45 @@ async def close_server(*args):
# # go to sleep until we get the first report
# await ws.wait_for_valid_data()

def check_and_append_sensor(sensor):
"""Check the sensor for validity, and append to appropriate list."""
if sensor not in SENSOR_TYPES:
if sensor not in IGNORED_SENSORS:
_LOGGER.warning("Unhandled sensor type %s", sensor)
return

def check_imp_metric_sensor(sensor):
"""Check if this is the wrong sensor for our config (imp/metric)."""
# Is this a metric or imperial sensor, lookup and skip
name, uom, kind, device_class, icon, metric = SENSOR_TYPES[sensor]
if "baro" in sensor:
if (conf[CONF_UNIT_BARO] == CONF_UNIT_SYSTEM_IMPERIAL
and metric == S_METRIC):
return
return False
if (conf[CONF_UNIT_BARO] == CONF_UNIT_SYSTEM_METRIC
and metric == S_IMPERIAL):
return
return False
if "rain" in sensor:
if (conf[CONF_UNIT_RAIN] == CONF_UNIT_SYSTEM_IMPERIAL
and metric == S_METRIC):
return
return False
if (conf[CONF_UNIT_RAIN] == CONF_UNIT_SYSTEM_METRIC
and metric == S_IMPERIAL):
return
return False
if "wind" in sensor:
if (conf[CONF_UNIT_WIND] == CONF_UNIT_SYSTEM_IMPERIAL
and metric == S_METRIC):
return
return False
if (conf[CONF_UNIT_WIND] == CONF_UNIT_SYSTEM_METRIC
and metric == S_IMPERIAL):
return
return False
return True

def check_and_append_sensor(sensor):
"""Check the sensor for validity, and append to appropriate list."""
if sensor not in SENSOR_TYPES:
if sensor not in IGNORED_SENSORS:
_LOGGER.warning("Unhandled sensor type %s", sensor)
return

# Is this a metric or imperial sensor, lookup and skip
if not check_imp_metric_sensor(sensor):
return

name, uom, kind, device_class, icon, metric = SENSOR_TYPES[sensor]
if kind == TYPE_SENSOR:
sensor_sensors.append(sensor)
if kind == TYPE_BINARY_SENSOR:
Expand Down Expand Up @@ -683,7 +694,10 @@ async def _async_ecowitt_update_cb(weather_data):
if sensor not in IGNORED_SENSORS:
_LOGGER.warning("Unhandled sensor type %s value %s, "
+ "file a PR.", sensor, weather_data[sensor])
if sensor not in sensor_sensors and sensor not in binary_sensors:
elif (sensor not in sensor_sensors
and sensor not in binary_sensors
and sensor not in IGNORED_SENSORS
and check_imp_metric_sensor(sensor)):
_LOGGER.warning("Unregistered sensor type %s value %s received.",
sensor, weather_data[sensor])
async_dispatcher_send(hass, DOMAIN)
Expand Down

0 comments on commit e6ac54f

Please sign in to comment.