Count of sockets/Lights

I copied a bit of code from here awhile back that worked perfectly until just recently (2024.9.x upgrades). What it did was count all of the lights/sockets that were on in each room. However now, each room reports zero even thought the entity is on.

    - name: "Number of Sockets On"
      unique_id: c838cee8-1919-4000-8fc0-d6587433e6fc
      attributes:
        navigation: sockets
        label: >
          {%- if this.state | int(0) > 0 -%}
          {{ this.state }} On
          {%- else -%}
          All Off
          {%- endif -%}
        entities: >
          {%- from 'tools.jinja' import list_entities -%}
          {{ list_entities(states.switch,device_class='outlet',state='on') }}
        count: >
          {%- from 'tools.jinja' import count_entities -%}
          {%- set ns = namespace(entities=[], tmp=[]) -%}
          {%- for s in states.switch | map(attribute='entity_id') | map('area_name') | unique | reject('none') | list -%}
            {%- set ns.tmp = ns.tmp + [ (s, count_entities(states.switch,device_class='outlet',state='on',area=s) | from_json )] -%}
          {%- endfor -%}
          {%- for key, value in ns.tmp -%} 
            {%- if key == 'House' -%}
              {%- set value = count_entities(states.switch,device_class='outlet',state='on') | from_json -%}
            {%- endif -%}
            {%- set ns.entities = ns.entities + [ (key, value)] -%}
          {%- endfor -%}
          {{ dict.from_keys(ns.entities) }}
      state: "{{ this.attributes.entities | count }}"
      icon: mdi:power-socket-uk

If I remove the device_class=outlet it provides the wrong count as it adds in items that are switches, but not outlets or lights.