pantherale0 / ha-nintendoparentalcontrols

Home Assistant integration for Nintendo Switch Parental Controls
MIT License
87 stars 7 forks source link

device.limit_time unsupported operand type NoneType and float #87

Closed dmz006 closed 8 months ago

dmz006 commented 8 months ago

System Health details

System Information

version core-2024.2.5
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.12.1
os_name Linux
os_version 6.1.73-haos-raspi
arch aarch64
timezone America/New_York
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 5000 Installed Version | 1.34.0 Stage | running Available Repositories | 1407 Downloaded Repositories | 14 HACS Data | ok
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Home Assistant Supervisor host_os | Home Assistant OS 12.0 -- | -- update_channel | stable supervisor_version | supervisor-2024.02.1 agent_version | 1.6.0 docker_version | 24.0.7 disk_total | 28.5 GB disk_used | 3.5 GB healthy | true supported | true board | rpi3-64 supervisor_api | ok version_api | ok installed_addons | Advanced SSH & Web Terminal (17.1.1)
Dashboards dashboards | 3 -- | -- resources | 6 views | 5 mode | storage
Recorder oldest_recorder_run | February 29, 2024 at 10:37 PM -- | -- current_recorder_run | March 1, 2024 at 4:56 PM estimated_db_size | 6.15 MiB database_engine | sqlite database_version | 3.44.2

Checklist

Nintendo Parental Controls mobile app

Describe the issue

I installed and configured the nintendo parential control plugin which appears to be working; however there appears to be a type error on limit_time (see below logs)

Reproduction steps

  1. Install HACS Nintendo Switch Parential Controls
  2. Install Integration for NSPC
  3. When configuring, copy and update access token following https://github.com/pantherale0/ha-nintendoparentalcontrols/issues/86
  4. Integration appears to work but then shows the errors provided ...

Debug logs

2024-03-01 17:46:35.198 ERROR (MainThread) [homeassistant.components.sensor] Error adding entities for domain sensor with platform nintendo_parental
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 533, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 782, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1325, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 989, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1110, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1047, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 995, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 549, in state
    value = self.native_value
            ^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nintendo_parental/sensor.py", line 44, in native_value
    return self._device.limit_time - (
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-03-01 17:46:35.279 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up nintendo_parental platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 352, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 533, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 782, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1325, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 989, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1110, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1047, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 995, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 549, in state
    value = self.native_value
            ^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nintendo_parental/sensor.py", line 44, in native_value
    return self._device.limit_time - (
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'
2024-03-01 17:46:47.687 ERROR (MainThread) [custom_components.nintendo_parental] Unexpected exception from <bound method DataUpdateCoordinator.async_refresh of <custom_components.nintendo_parental.coordinator.NintendoUpdateCoordinator object at 0x7f61777080>>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/debounce.py", line 114, in _handle_timer_finish
    await task
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 289, in async_refresh
    await self._async_refresh(log_failures=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 412, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 183, in async_update_listeners
    update_callback()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 492, in _handle_coordinator_update
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 989, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1110, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1047, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 995, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 549, in state
    value = self.native_value
            ^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nintendo_parental/sensor.py", line 44, in native_value
    return self._device.limit_time - (
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'
2024-03-01 18:06:15.801 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 256, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 412, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 183, in async_update_listeners
    update_callback()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 492, in _handle_coordinator_update
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 989, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1110, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1047, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 995, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 549, in state
    value = self.native_value
            ^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nintendo_parental/sensor.py", line 44, in native_value
    return self._device.limit_time - (
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'

Diagnostics dump

No response

JokerGermany commented 8 months ago

Have this too, need to restart home assistant to let it work again. For me it was bedtime_limit

JokerGermany commented 8 months ago

have to correct me, looks like it's not working anymore -__-

pantherale0 commented 8 months ago

Yes, I can replicate this when the parental controls app is set to not restricted. A new update will be released soon that has a couple of major changes, around this but also handling of the play time limit is now a number entity rather than time entity:

image

JokerGermany commented 8 months ago

Indeed playtime was set to unrestricted :thinking:

pantherale0 commented 8 months ago

Resolved in 2024.3.0 (released as beta)

dmz006 commented 8 months ago

How do I set HACS to use the beta release so I can test?

JokerGermany commented 8 months ago

How do I set HACS to use the beta release so I can test?

  1. open hacs
  2. Integration
  3. Nintendo Switch Parental Controls
  4. 3 dots on top right
  5. retry downloading
dmz006 commented 8 months ago

Thank you - been running for 20 minutes now and no errors.

JokerGermany commented 8 months ago

@pantherale0 I am asking because i have to change my scripts. In the actual beta of

2024.3.0

only the variable name for play_time_limit was changed? Am I correct?

pantherale0 commented 8 months ago

Yes, the entity ID would have changed. Due to a previous change introduced in an earlier release it will probably include the name of the switch itself too.

To confirm what it is I would go into the Nintendo Switch device in Home Assistant (from the integrations page) and check the number. entity.