sensors: measurement request fix

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2023-04-17 08:08:13 -04:00
parent eff090170c
commit 53d9522c06
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
1 changed files with 10 additions and 14 deletions

View File

@ -241,7 +241,6 @@ class Sensors:
changed_data[sensor_name] = sensor.last_value changed_data[sensor_name] = sensor.last_value
if changed_data: if changed_data:
self.server.send_event(SENSOR_EVENT_NAME, changed_data) self.server.send_event(SENSOR_EVENT_NAME, changed_data)
return eventtime + SENSOR_UPDATE_TIME return eventtime + SENSOR_UPDATE_TIME
async def component_init(self) -> None: async def component_init(self) -> None:
@ -254,7 +253,6 @@ class Sensors:
) )
self.sensors_update_timer.start() self.sensors_update_timer.start()
except Exception as e: except Exception as e:
logging.exception(e) logging.exception(e)
@ -274,25 +272,23 @@ class Sensors:
sensor_name: str = web_request.get_str("sensor") sensor_name: str = web_request.get_str("sensor")
if sensor_name not in self.sensors: if sensor_name not in self.sensors:
raise self.server.error(f"No valid sensor named {sensor_name}") raise self.server.error(f"No valid sensor named {sensor_name}")
sensor = self.sensors[sensor_name] sensor = self.sensors[sensor_name]
return sensor.get_sensor_info() return sensor.get_sensor_info()
async def _handle_sensor_measurements_request( async def _handle_sensor_measurements_request(
self, web_request: WebRequest self, web_request: WebRequest
) -> Dict[str, Dict[str, Any]]: ) -> Dict[str, Dict[str, Any]]:
sensor_name: str = web_request.get_str("sensor", "") sensor_name: str = web_request.get_str("sensor", "")
if sensor_name and sensor_name not in self.sensors: if sensor_name:
raise self.server.error(f"No valid sensor named {sensor_name}") sensor = self.sensors.get(sensor_name, None)
if sensor is None:
output = { raise self.server.error(f"No valid sensor named {sensor_name}")
key: sensor.get_sensor_measurements() return {sensor_name: sensor.get_sensor_measurements()}
for key, sensor in self.sensors.items() else:
if sensor_name is "" or key == sensor_name return {
} key: sensor.get_sensor_measurements()
for key, sensor in self.sensors.items()
return output }
def close(self) -> None: def close(self) -> None:
self.sensors_update_timer.stop() self.sensors_update_timer.stop()