Excluding 'NaN' Values from sensors

I am using the air quality custom integration for PurpleAir, and showing a historical graph of the Air Quality Index for my immediate area. The problem is that the graph frequently displays “NaN” as the AQI value. Checking the sensor status using Developer Tools shows that when this occurs, the sensor state is being reported as “unknown,” instead of the expected numerical value of 0 to whatever. I tried to use a filter to exclude any result that was outside of the range 1-800, but that seems to have no effect when the result is not a numeric value but is instead a string:

  - platform: filter
    name: "filtered TD AQI"
    entity_id: sensor.tartan_druim_air_quality_index
      - filter: range
        lower_bound: 1
        upper_bound: 800

Is there a way to exclude these “unknown” values so that, e.g., if the value is “unknown” then it uses the last known numerical value? Thanks.