home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.69k stars 30.82k forks source link

Failed to call service media_player/turn_on. Incorrect MAC address format #102352

Closed seblu closed 1 year ago

seblu commented 1 year ago

The problem

The samsungtv integration randomly return Failed to call service media_player/turn_on. Incorrect MAC address format.

Screenshot_20231019_203338

I suspect the issue come from the .storage/core.device_registry file which contains a mac defined as "none".

        "connections": [
          [
            "mac",
            "none"
          ],
          [
            "mac",
            "ab:cd:ef:01:23:45"
          ]
        ],

I tried to remove the none mac, but the integration add it again, sometimes right after HA restart. I removed the integration and added it back. This fixed the issue for some times but the none mac returned.

What version of Home Assistant Core has the issue?

2023.10.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

samsungtv

Link to integration documentation on our website

https://www.home-assistant.io/integrations/samsungtv/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2023-10-19 20:51:50.727 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [281472370404032] Incorrect MAC address format
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 226, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 2012, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2049, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 235, in handle_service
    return await service.entity_service_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 876, in entity_service_call
    response_data = await _handle_entity_call(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 948, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/samsungtv/media_player.py", line 423, in async_turn_on
    await self.hass.async_add_executor_job(self._wake_on_lan)
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/samsungtv/media_player.py", line 413, in _wake_on_lan
    send_magic_packet(self._mac, ip_address=self._host)
  File "/usr/local/lib/python3.11/site-packages/wakeonlan.py", line 56, in send_magic_packet
    packets = [create_magic_packet(mac) for mac in macs]
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/wakeonlan.py", line 56, in <listcomp>
    packets = [create_magic_packet(mac) for mac in macs]
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/wakeonlan.py", line 31, in create_magic_packet
    raise ValueError("Incorrect MAC address format")
ValueError: Incorrect MAC address format

Additional information

No response

home-assistant[bot] commented 1 year ago

Hey there @chemelli74, @epenet, mind taking a look at this issue as it has been labeled with an integration (samsungtv) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `samsungtv` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign samsungtv` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


samsungtv documentation samsungtv source (message by IssueLinks)

joostlek commented 1 year ago

I think this might be the cause of #98583

chemelli74 commented 1 year ago

I fear it's hard to reproduce.

If you are available for some tests, we may add extra logging to the integration to understand where this issue starts from.

seblu commented 1 year ago

@joostlek I also have 2 Samsung TVs but so far they are well detected as 2 devices. Screenshot_20231019_235318

@chemelli74 sure, I've a test server, what extra logging are you looking for?

joostlek commented 1 year ago

But what I'm guessing is that this also happens to the people in that issue, causing both TVs to collapse. I'm guessing your other TV doesn't set Mac to none. (Fyi, devices collapse into 1 device if the connections field match (the place where you saw Mac "none"))

seblu commented 1 year ago

I removed the "none" mac from the connections list of both TVs and I set the logger homeassistant.components.samsungtv to debug. This time restart didn't reintroduce the mac none, so I'll wait for it.

seblu commented 1 year ago

So far, so good. Patience.

jq  '.data.devices[]|select(.manufacturer[:7]=="Samsung")|{connections, model, manufacturer}' ~/config/.storage/core.device_registry
{
  "connections": [
    [
      "mac",
      "aa:bb:cc:dd:ee:ff"
    ]
  ],
  "model": "UE43NU7405",
  "manufacturer": "Samsung"
}
{
  "connections": [
    [
      "mac",
      "00:11:22:33:44:55"
    ]
  ],
  "model": "UE65NU7405",
  "manufacturer": "Samsung Electronics"
seblu commented 1 year ago

I get some news. The none mac is back.

From the log analysis, my best guess is that the 'none' mac is coming from the wifiMac field. From time to time, it is first fetched as none , maybe when the TV is waking up from a deeper sleep.

2023-10-29 00:12:58.615 DEBUG (MainThread) [homeassistant.components.samsungtv] Samsung device found via DHCP: DhcpServiceInfo(ip='192.168.1.2', hostname='samsung', macaddress='01234578abcd')
2023-10-29 00:12:58.615 DEBUG (MainThread) [homeassistant.components.samsungtv] Found entry matching host for 192.168.1.2
2023-10-29 00:12:59.239 DEBUG (MainThread) [homeassistant.components.samsungtv] Device info on 192.168.1.2 is: {'device': {'FrameTVSupport': 'false', 'GamePadSupport': 'true', 'ImeSyncedSupport': 'true', 'OS': 'Tizen', 'TokenAuthSupport': 'true', 'VoiceSupport': 'true', 'countryCode': 'FR', 'description': 'Samsung DTV RCR', 'developerIP': '0.0.0.0', 'developerMode': '1', 'duid': 'uuid:**REDACTED**', 'firmwareVersion': 'Unknown', 'id': 'uuid:**REDACTED**', 'ip': '', 'model': '18_KANTME_UHD', 'modelName': 'UE43NU7405', 'name': '**REDACTED**', 'networkType': 'none', 'resolution': '3840x2160', 'smartHubAgreement': 'true', 'type': 'Samsung SmartTV', 'udn': 'uuid:**REDACTED**', 'wifiMac': 'none'}, 'id': 'uuid:**REDACTED**', 'isSupport': '{"DMP_DRM_PLAYREADY":"false","DMP_DRM_WIDEVINE":"false","DMP_available":"true","EDEN_available":"true","FrameTVSupport":"false","ImeSyncedSupport":"true","TokenAuthSupport":"true","remote_available":"true","remote_fourDirections":"true","remote_touchPad":"true","remote_voiceControl":"true"}\n', 'name': '**REDACTED**', 'remote': '1.0', 'type': 'Samsung SmartTV', 'uri': 'https://192.168.1.2:8002/api/v2/', 'version': '2.0.25'}
2023-10-29 00:12:59.239 DEBUG (MainThread) [homeassistant.components.samsungtv] Fetching rest info via 8002 was successful: {'device': {'FrameTVSupport': 'false', 'GamePadSupport': 'true', 'ImeSyncedSupport': 'true', 'OS': 'Tizen', 'TokenAuthSupport': 'true', 'VoiceSupport': 'true', 'countryCode': 'FR', 'description': 'Samsung DTV RCR', 'developerIP': '0.0.0.0', 'developerMode': '1', 'duid': 'uuid:**REDACTED**', 'firmwareVersion': 'Unknown', 'id': 'uuid:**REDACTED**', 'ip': '', 'model': '18_KANTME_UHD', 'modelName': 'UE43NU7405', 'name': '**REDACTED**', 'networkType': 'none', 'resolution': '3840x2160', 'smartHubAgreement': 'true', 'type': 'Samsung SmartTV', 'udn': 'uuid:**REDACTED**', 'wifiMac': 'none'}, 'id': 'uuid:**REDACTED**', 'isSupport': '{"DMP_DRM_PLAYREADY":"false","DMP_DRM_WIDEVINE":"false","DMP_available":"true","EDEN_available":"true","FrameTVSupport":"false","ImeSyncedSupport":"true","TokenAuthSupport":"true","remote_available":"true","remote_fourDirections":"true","remote_touchPad":"true","remote_voiceControl":"true"}\n', 'name': '**REDACTED**', 'remote': '1.0', 'type': 'Samsung SmartTV', 'uri': 'https://192.168.1.2:8002/api/v2/', 'version': '2.0.25'}, checking for encrypted
2023-10-29 00:12:59.240 DEBUG (MainThread) [homeassistant.components.samsungtv] Found entry matching host for 192.168.1.2
2023-10-29 00:12:59.241 DEBUG (MainThread) [homeassistant.components.samsungtv] Calling debouncer to get a reload after cooldown
2023-10-29 00:13:02.048 DEBUG (MainThread) [homeassistant.components.samsungtv] Device info on 192.168.1.2 is: {'device': {'FrameTVSupport': 'false', 'GamePadSupport': 'true', 'ImeSyncedSupport': 'true', 'OS': 'Tizen', 'TokenAuthSupport': 'true', 'VoiceSupport': 'true', 'countryCode': 'FR', 'description': 'Samsung DTV RCR', 'developerIP': '0.0.0.0', 'developerMode': '1', 'duid': 'uuid:**REDACTED**', 'firmwareVersion': 'Unknown', 'id': 'uuid:**REDACTED**', 'ip': '192.168.1.2', 'model': '18_KANTME_UHD', 'modelName': 'UE43NU7405', 'name': '**REDACTED**', 'networkType': 'wired', 'resolution': '3840x2160', 'smartHubAgreement': 'true', 'type': 'Samsung SmartTV', 'udn': 'uuid:**REDACTED**', 'wifiMac': 'ab:cd:ef:01:23:45'}, 'id': 'uuid:**REDACTED**', 'isSupport': '{"DMP_DRM_PLAYREADY":"false","DMP_DRM_WIDEVINE":"false","DMP_available":"true","EDEN_available":"true","FrameTVSupport":"false","ImeSyncedSupport":"true","TokenAuthSupport":"true","remote_available":"true","remote_fourDirections":"true","remote_touchPad":"true","remote_voiceControl":"true"}\n', 'name': '**REDACTED**', 'remote': '1.0', 'type': 'Samsung SmartTV', 'uri': 'https://192.168.1.2:8002/api/v2/', 'version': '2.0.25'}
2023-10-29 00:13:02.048 DEBUG (MainThread) [homeassistant.components.samsungtv] TV 192.168.1.2 state updated to on

For the record, the TV is connected by wire.

romanad commented 1 year ago

Guys, can't turn on my TV Samsung NU7300

I have error: "Failed to call service media_player/turn_on. Incorrect MAC address format"

This is what in my configuration.yaml:

media_player:

epenet commented 1 year ago

@romanad you are using a custom component so you should post on the custom component repository instead. Please don't polute the thread here with samsungtv_tizen

epenet commented 1 year ago

@seblu thanks for the diagnostics. I have created PR #103512 to fix this.