Formatting Phone Number

I have created the following template sensor, which takes the cid_name attribute from sensor.phone_modem and makes it its own entity while leaving the other two attributes in place. It works great, but I would really like to format the number attribute like a US telephone number: (xxx) xxx-xxxx

Can someone help me with this, please?

  - sensor:
      - name: phone_call
        icon: mdi:phone-classic
        state: >
          {% if is_state('sensor.phone_modem', 'callerid') %}
            {{ state_attr('sensor.phone_modem', 'cid_name') }}
          {% else %}
            idle
          {% endif %}
        attributes:
          number: "{{ state_attr('sensor.phone_modem', 'cid_number') }}"
          time: "{{ state_attr('sensor.phone_modem', 'cid_time') }}"

This does the trick:

   - sensor:
      - name: phone_call
        unique_id: phone_call
        icon: mdi:phone-classic
        state: >
          {% if is_state('sensor.phone_modem', 'callerid') %}
            {{ state_attr('sensor.phone_modem', 'cid_name') }}
          {% else %}
            idle
          {% endif %}
        attributes:
          number: >
            {{ ('({0:03}) {1:03}-{2:04}'.format((state_attr('sensor.phone_modem', 'cid_number') | int) // 10000000,
            (state_attr('sensor.phone_modem', 'cid_number') | int) % 10000000 // 10000,
            (state_attr('sensor.phone_modem', 'cid_number') | int) % 10000) ) }}
          time: "{{ state_attr('sensor.phone_modem', 'cid_time') }}"