Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RC5 mappings are not compatible with the AVR390 line #2

Open
sam808 opened this issue Oct 5, 2020 · 38 comments
Open

RC5 mappings are not compatible with the AVR390 line #2

sam808 opened this issue Oct 5, 2020 · 38 comments

Comments

@sam808
Copy link

sam808 commented Oct 5, 2020

The current mappings of RC5 codes (specifically for input selection) don't map to the RC5 codes for the AVR390. https://www.arcam.co.uk/ugc/tor/avr390/RS232/RS232_860_850_550_390_250_SH274E_D_181018.pdf

For instance,

class RC5Codes(enum.Enum): SELECT_STB = bytes([16, 1])

.. and per the above spec, STB 16-100 0x10 - 0x64

This results in all input selection erroring with a CommandInvalidAtThisTime error.

@elupus
Copy link
Owner

elupus commented Oct 5, 2020

Yes annoying. Why could they not keep to the same standard... Will see if I can look at resolving this.

@sam808
Copy link
Author

sam808 commented Oct 5, 2020

Yes annoying. Why could they not keep to the same standard... Will see if I can look at resolving this.

Right!? I cloned to test with HA here https://github.com/sam808/arcam_fmj_avr390 with changes to the code mapping, but that'll break any of the existing devices. I thought about adding AVR390_xxx code mappings, but to be fair, this is the first time I'm using Python in any meaningful way, so it's going slow.

@fastknight
Copy link

I have an AVR550 and an AVR850 with same issues as above - both of these units do not accept the codes being sent, though Volume works fine so must the same code across all devices.

Do we know what unit is this module intended for in terms of the codes currently embedded into the code?

Thanks.

@elupus
Copy link
Owner

elupus commented May 17, 2021

450

@fastknight
Copy link

fastknight commented Jul 30, 2021

I saw there was an update to this repo and see references in the code to different API versions now. Is there a way to use this integration with the annoyingly different AVR390/550/850 RC5 codes now or should I use the forked version from @sam808 ?

@sam808
Copy link
Author

sam808 commented Jul 30, 2021

I saw there was an update to this repo and see references in the code to different API versions now. Is there a way to use this integration with the annoyingly different AVR390/550/850 RC5 codes now or should I use the forked version from @sam808 ?

@fastknight I have not seen these changes merged into the main repo, but I am currently using my fork with an AVR390 and you’re welcome to it. Aside from some annoying comm issues with the AVR, the mapping works, but also requires config in HA if you want any custom input names to show up.

@elupus
Copy link
Owner

elupus commented Jul 30, 2021

I've started to work on getting some additional support in. Will need help testing later.

@fastknight
Copy link

Hey many thanks @sam808 - I will try pulling your component into my HAS install and see how it goes as i believe the 390 and 550 share the same codes. I have no idea how Arcam have managed to change codes across these models - so frustrating! :)

@elupus
Copy link
Owner

elupus commented Jul 30, 2021

So far the only fixes is for sound modes. No fixes for rc5 codes yet, so you can hold of for now.

@fastknight
Copy link

Yep I could see those added.

Theres lots of RC5 code changes for inputs etc, I'm happy to help pull all those out the Arcam docs if thats of any help as its probably a right pain to sift through it all.

@elupus
Copy link
Owner

elupus commented Jul 31, 2021

If anybody could help out with filling out the rc5 mappings here:

RC5CODE_DECODE_MODE_MCH = {

for the API860_SERIES (should include 360) too, we should be closer to support.

@fastknight
Copy link

I can do this - how do you want the codes presented? I have the Arcam document with all the codes so can work through it and create a 390series API section if you like? It also shares the same codes as 550/850/860 apparently.

@elupus
Copy link
Owner

elupus commented Aug 1, 2021

I have the doc as well. I wanted a pull request with the codes added where i mentioned above. I don't benefit much from having extracted codes, i can do that while adding them to the python lib.

@elupus
Copy link
Owner

elupus commented Aug 1, 2021

I've added the support to the lib now here: ffa0f37 would be nice to get another set of eyes on the mappings.

I've not verified this at all yet with home assistant. Will need to be done once we open a pull request for it.

@fastknight
Copy link

Thanks, I will run through the codes and check/add them against the docs.

I can check they work with my 850 receiver locally before creating a pull request, how do I get the addon code to use the API860_series RC5 codes instead of the default API450_series.

Sorry I'm not a developer but am technically proficient-ish

@elupus
Copy link
Owner

elupus commented Aug 1, 2021

You should be able to bump the version number in the manifest file for arcam_fmj component in home assistant once I've created a release for 0.9.0. Then it should hopefully detect it as an 850 and use those codes.

@fastknight
Copy link

Ah very cool - many thanks. I will run through the codes in the Arcam docs as a second set of eyes and report any differences.

Many thanks for updating the script - really appreciated.

@elupus
Copy link
Owner

elupus commented Aug 1, 2021

I've opened a draft pull request on home assistant here: home-assistant/core#53843

I need help testing this out on real devices.

@fastknight
Copy link

I tried to test this out - I git cloned a copy of 0.9 into /config/custom_components but had same errors as before when switching inputs so I assumed HA was still using the old version.

How do I force my install to use the new 0.9 version to do testing? I had thought custom_components folder overrode builtin components but maybe not?

@elupus
Copy link
Owner

elupus commented Aug 2, 2021

It's not this repo you need to put in custom components. It's the files from
https://github.com/elupus/home-assistant/tree/arcam_fixes/homeassistant/components/arcam_fmj

That is the arcam component in home assistant with me changes for it to use the new version of the library.

You also need to add a "version": "9.9.9" tag to the manifest file there for it to be accepted as a custom component.

@fastknight
Copy link

Apologies - this is my first time with this. I did the following;

  1. Deleted the Arcam integration and devices in HAS to clean up.

  2. Downloaded files from https://github.com/elupus/home-assistant/tree/arcam_fixes/homeassistant/components/arcam_fmj and placed them in /config/custom_components/arcam_fmj

  3. Edited /config/custom_components/arcam_fmj/manifest.json with the follow;
    {
    "domain": "arcam_fmj",
    "name": "Arcam FMJ Receivers",
    "version": "9.9.9". <----- Added version number
    .......

  4. Restarted HA

Arcam device is always found, but always comes up as unavailable in the integration.

Many apologies for taking up so much time!

@elupus
Copy link
Owner

elupus commented Aug 2, 2021

Looks correct. Can you check your logs for errors/warnings?

@fastknight
Copy link

I removed the new code from the custom_component folder and confirmed it all went back to semi-working state (ie wrong codes being sent to receiver) but device was available again in HA (power button works for example).

Then I re-added the https://github.com/elupus/home-assistant/tree/arcam_fixes/homeassistant/components/arcam_fmj back into custom_components again, am now getting device as available but still getting code errors. I restarted HA, same thing.

Though I must admit to being confused as to how HA is even getting access to the new codes as the files in that link don't include the code shown here; https://github.com/elupus/arcam_fmj/tree/master/src/arcam/fmj

I'm unfamiliar with how this works - so I must admit I expected it to be a case of dropping new Integration code into a folder to override existing shipping code but seems way more complex that. It's also hard to tell in HA what version of the integration is being used?

@elupus
Copy link
Owner

elupus commented Aug 2, 2021

You can test the library manually first on a standard computer using python.

pip install arcam-fmj
arcam-fmj state --host x.x.x.x

That should give you a printout of current state, as well as what model you have.

Ps. Did you remember to add the version key to manifest.json after you copied back? Otherwise it is ignoring the custom component install.

@elupus
Copy link
Owner

elupus commented Aug 2, 2021

The HA logs look like the old version. My guess is it didn't accept the custom component.

The other log is more confusing. Can you make sure home assistant doesn't have arcam integration enabled when testing the command line stuff.

The receiver is weird. Also next time run with.

arcam-fmj --verbose state --host x.x.x.x

@fastknight
Copy link

I agree I just don't think its using the new component under /config - I'm using HassOS if that makes any difference so I can't see /usr/src/homeassistant as its part of the HA docker image which I cant easily access not that it would make much of a difference I guess.

@fastknight
Copy link

Ok realised I was missing the , after version. Think its picking it up now, but still getting code errors when switching inputs.

Power control is fine
Volume control is fine
DAB input selection is fine.
All other inputs have an error.

@fastknight
Copy link

Success - removed, resetup and restarted and I can switch inputs now - will continue testing.

@elupus
Copy link
Owner

elupus commented Aug 3, 2021

Check the sound modes too.

@fastknight
Copy link

fastknight commented Aug 3, 2021

Been testing it this morning - manually changing inputs/volume on the media card in Lovelace work great.

If I setup a scene with the Amp on and in a particular input it I get an error every time with a reference to turn on command and the scene does not execute for the Amp. Seems like its confused about its on state maybe.

Error message is below.

Logger: homeassistant.components.websocket_api.http.connection
Source: custom_components/arcam_fmj/media_player.py:202
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 12:43:14 (9 occurrences)
Last logged: 12:57:10

[140687918626944] 'ac':133, 'zn':1, 'cc':8, 'data':b'\x10{'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 185, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1491, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1526, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 658, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 811, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 695, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/homeassistant/scene.py", line 313, in async_activate
    await async_reproduce_state(
  File "/usr/src/homeassistant/homeassistant/helpers/state.py", line 116, in async_reproduce_state
    await asyncio.gather(
  File "/usr/src/homeassistant/homeassistant/helpers/state.py", line 110, in worker
    await platform.async_reproduce_states(  # type: ignore
  File "/usr/src/homeassistant/homeassistant/components/media_player/reproduce_state.py", line 113, in async_reproduce_states
    await asyncio.gather(
  File "/usr/src/homeassistant/homeassistant/components/media_player/reproduce_state.py", line 72, in _async_reproduce_states
    await call_service(SERVICE_TURN_ON, [])
  File "/usr/src/homeassistant/homeassistant/components/media_player/reproduce_state.py", line 57, in call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1491, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1526, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 658, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 811, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 695, in _handle_entity_call
    await result
  File "/config/custom_components/arcam_fmj/media_player.py", line 202, in async_turn_on
    await self._state.set_power(True)
  File "/usr/local/lib/python3.9/site-packages/arcam/fmj/state.py", line 208, in set_power
    await self._client.request(
  File "/usr/local/lib/python3.9/site-packages/arcam/fmj/client.py", line 186, in request
    raise ResponseException.from_response(response)
arcam.fmj.CommandInvalidAtThisTime: 'ac':133, 'zn':1, 'cc':8, 'data':b'\x10{'

@elupus
Copy link
Owner

elupus commented Aug 3, 2021

That seems to be the turn on command failing. I wonder if it rejects turn on, if it is already on.

@fastknight
Copy link

Thats what it looks like. The scenes do not seem to run well at all - interested to know how your model copes.

I think I will have to send individual commands with pauses rather than use scenes as it just seems to randomly reject input changes, even if the device is starting up from being off.

@elupus
Copy link
Owner

elupus commented Aug 3, 2021

Could be a timing issue. If it's slow to start up, it might reject further commands.

@elupus
Copy link
Owner

elupus commented Aug 6, 2021

What happens if you call turn on service for media player directly from developer pages in home assistant? do you get an error then too?

@fastknight
Copy link

Did some tests here using Developer Tools - looks like a timing issue;

First ON command from services works fine, sending another ON command just creates an Unknown Error.
First OFF command from services also works fine, sending another OFF Command does not generate an error.
Changing sources in Developer Tools all works fine once powered up.
Sending an On command, and then a change Source command straight away creates the error.

So for a scene I'd need to add a pause between the On command and anything subsequent or use a script I guess.

@fastknight
Copy link

Also for sound modes I get:

STERRO: Error
DTS_NEURAL_X: Error
DTS_VIRTUAL_X: Error
DOLBY_PL: Error
DTS_NEO_6_CINEMA: OK
DTS_NEO_6_MUSIC: OK
MCH_STERO: Error

@elupus
Copy link
Owner

elupus commented Aug 8, 2021

Odd that neither stereo or mch_stereo works. What type of source was this on? was it a 2ch source or not?

@elupus
Copy link
Owner

elupus commented Aug 8, 2021

I just checked mine. I can send any number of turn_on service calls without error to mine. But you say yours will always fail if the device is already turned on?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants