Giter Site home page Giter Site logo

Comments (27)

MrDuco avatar MrDuco commented on September 26, 2024 1

With beta-7
2021-12-05 22:32:44 ERROR (MainThread) [homeassistant.components.switch] Error while setting up sector platform for switch
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform
await asyncio.shield(task)
File "/config/custom_components/sector/switch.py", line 41, in async_setup_entry
switchlist.append(SectorAlarmSwitch(sector_hub, coordinator, description))
File "/config/custom_components/sector/switch.py", line 64, in init
self._id: str = self._hub.get_id[self._serial]
TypeError: 'method' object is not subscriptable

from sector.

gjohansson-ST avatar gjohansson-ST commented on September 26, 2024 1

Ok. Did a beta9 release now. I would think it should fix the issue.
Given I have changed a lot of things e.g. cleanup make sure you test state and control on all stuff so not only switch.

BETA 9 REQUIRES HA 2012.12 so make sure you update to it before running beta9

from sector.

gjohansson-ST avatar gjohansson-ST commented on September 26, 2024

New beta to test (beta4)

from sector.

MrDuco avatar MrDuco commented on September 26, 2024

Downloaded and re-installed. This is now seen in log:
2021-12-05 14:19:29 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry sa_02829975 for switch
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 304, in async_setup
result = await component.async_setup_entry(hass, self) # type: ignore
File "/usr/src/homeassistant/homeassistant/components/switch/init.py", line 79, in async_setup_entry
return await component.async_setup_entry(entry)
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 149, in async_setup_entry
platform = await async_prepare_setup_platform(
File "/usr/src/homeassistant/homeassistant/setup.py", line 334, in async_prepare_setup_platform
platform = integration.get_platform(domain)
File "/usr/src/homeassistant/homeassistant/loader.py", line 530, in get_platform
cache[full_name] = self._import_platform(platform_name)
File "/usr/src/homeassistant/homeassistant/loader.py", line 535, in _import_platform
return importlib.import_module(f"{self.pkg_path}.{platform_name}")
File "/usr/local/lib/python3.9/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1030, in _gcd_import
File "", line 1007, in _find_and_load
File "", line 986, in _find_and_load_unlocked
File "", line 680, in _load_unlocked
File "", line 850, in exec_module
File "", line 228, in _call_with_frames_removed
File "/config/custom_components/sector/switch.py", line 51, in
class SectorAlarmSwitch(CoordinatorEntity, SwitchEntity):
File "/config/custom_components/sector/switch.py", line 78, in SectorAlarmSwitch
def extra_state_attributes(self) -> dict(str, str):
TypeError: dict expected at most 1 argument, got 2

from sector.

gjohansson-ST avatar gjohansson-ST commented on September 26, 2024

Downloaded and re-installed. This is now seen in log: 2021-12-05 14:19:29 ERROR (MainThread)

Not funny as I spotted it already yesterday but apparently forgot to fix it in switch while it's fixed in the other platforms.
Now released beta5 fixing this

from sector.

MrDuco avatar MrDuco commented on September 26, 2024

Ok, no errors in log now. but no switches can be found in HA. Tried looking for them in dev. tools and also during installation of Sector they are not shown (may they should not be shown here?)
image

from sector.

gjohansson-ST avatar gjohansson-ST commented on September 26, 2024

Ok, I was resetting my own list so therefore no switches appearing.
New beta released which I really hope should now also show the switches.
Thanks for making an effort testing my stuff!

from sector.

MrDuco avatar MrDuco commented on September 26, 2024

No, thank you for making this effort even thou not using sector anymore!
This is now shown in log
2021-12-05 17:32:15 ERROR (MainThread) [homeassistant.components.switch] Error while setting up sector platform for switch
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform
await asyncio.shield(task)
File "/config/custom_components/sector/switch.py", line 38, in async_setup_entry
identification = await sector_hub.get_id(switch)
File "/config/custom_components/sector/init.py", line 241, in get_id
return switch["id"]
KeyError: 'id'

from sector.

gjohansson-ST avatar gjohansson-ST commented on September 26, 2024

Simple *** misspelling...
New beta made

from sector.

gjohansson-ST avatar gjohansson-ST commented on September 26, 2024

Beta 8 released.
Pretty close now to work... Almost guessing here this will be the last beta 🤞

from sector.

MrDuco avatar MrDuco commented on September 26, 2024

Sorry. still some new errors in log:
2021-12-06 19:07:20 ERROR (MainThread) [custom_components.sector] Timed out when connecting to Sector
2021-12-06 19:07:35 ERROR (MainThread) [custom_components.sector] Timed out when connecting to Sector
2021-12-06 19:07:47 ERROR (MainThread) [homeassistant.components.websocket_api.messages] Unable to serialize to JSON. Bad data found at $.event(Event: state_changed).data.new_state(State: switch.hallen_nere).attributes.Id=<coroutine object SectorAlarmHub.get_id at 0x7f1f75ac1640>(<class 'coroutine'>
2021-12-06 19:07:47 ERROR (MainThread) [homeassistant.components.websocket_api.messages] Unable to serialize to JSON. Bad data found at $.event(Event: state_changed).data.new_state(State: switch.koket).attributes.Id=<coroutine object SectorAlarmHub.get_id at 0x7f1f75ac16c0>(<class 'coroutine'>
2021-12-06 19:07:47 ERROR (MainThread) [homeassistant.components.websocket_api.messages] Unable to serialize to JSON. Bad data found at $.event(Event: state_changed).data.new_state(State: switch.vardagsrum).attributes.Id=<coroutine object SectorAlarmHub.get_id at 0x7f1f75ac1740>(<class 'coroutine'>

And then there is this which I don't know if it needs to be handled because I think it is one of my switches that are inactive state, but it fills the log.
2021-12-06 19:07:47 ERROR (MainThread) [homeassistant.components.sensor] Error adding entities for domain sensor with platform sector
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 382, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 607, in _async_add_entity
await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 715, in add_to_platform_finish
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 486, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 519, in _async_write_ha_state
state = self._stringify_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 492, in _stringify_state
if (state := self.state) is None:
File "/config/custom_components/sector/sensor.py", line 90, in state
return self._hub.temp_state[self._serial]
KeyError: '24901XXXXXX'

And unfortunately all of them are marked as unavailable
image

from sector.

Ubiquitous-X avatar Ubiquitous-X commented on September 26, 2024

One thing to watch out for are those infamous soft bans Sector hands out like it was candy. Those first two lines you got there, with the "timed out when connecting to Sector" message, with 15 seconds in between, might be that you got banned. That might be why Home Assistant can't add the entities.
Those soft bans are usually lifted after a few hours. But it is on a per device level, so you are probably still able to connect with your Sector app as usual.

from sector.

MrDuco avatar MrDuco commented on September 26, 2024

Tried to do some debugging on my own.
To get rid of the JSON serialze error I changed in switch.py line 64
from:
self._id: str = self._hub.get_id(self._serial)
to:
self._id: str = self._hub._switchid[self._serial]

in init.py on line 290 and 295 I think there is a typo
was
f"{API_URL}TurnOffSmartplug?switchId={identity}&panelId={self.panel_id}",
and it think it should be
:
f"{API_URL}/Panel/TurnOffSmartplug?switchId={identity}&panelId={self._panel_id}",

Now I can see that is tries to send to Secotr but status of the Switch does not change and it reverts back in UI to "on" no matter what state switch is in.

from sector.

MrDuco avatar MrDuco commented on September 26, 2024

Unfortunatlly this caused the temprature sensors to report state "Unknown" but graph shows correct tempratures

image
image

Switch can be controlled but updates are really slow sometimes and often it reverts back to previous state before changing after some time
image

also get this when I try to turn the Switch on - think the error is an missing "await" on row 88
/workspaces/core/config/custom_components/sector/switch.py:88: RuntimeWarning: coroutine 'SectorAlarmSwitch.async_triggerswitch' was never awaited
Coroutine created at (most recent call last)
File "/usr/local/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/local/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/workspaces/core/homeassistant/main.py", line 331, in
sys.exit(main())
File "/workspaces/core/homeassistant/main.py", line 318, in main
exit_code = runner.run(runtime_conf)
File "/workspaces/core/homeassistant/runner.py", line 121, in run
return loop.run_until_complete(setup_and_run_hass(runtime_config))
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 629, in run_until_complete
self.run_forever()
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 596, in run_forever
self._run_once()
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1882, in _run_once
handle._run()
File "/usr/local/lib/python3.9/asyncio/events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "/workspaces/core/config/custom_components/sector/switch.py", line 88, in async_turn_on
self.async_triggerswitch("On")
self.async_triggerswitch("On")
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

from sector.

gjohansson-ST avatar gjohansson-ST commented on September 26, 2024

Do you have 2012.12 version of HA (given the temp issue above)?

from sector.

MrDuco avatar MrDuco commented on September 26, 2024

Do you mean 2021.12 version or Above?
I have two HA servers on for dev
image

And my prod HA
image

both had same issue...

updated to beta-10 and restarted and now temp seems to work fine in both.

What does still not work is that switch reverts back to prev. state
It correctly update state from switch during start up
If it is "on" i can turn it "off" i UI and switch turns off
It then reverts back to "on" in UI, so to change stat again you have to double click in UI

from sector.

gjohansson-ST avatar gjohansson-ST commented on September 26, 2024

Yeah. I meant 2021.12
I did do beta10 in the meantime just to fix the sensor and the await problem you made a PR for.
Does the plug itself work with pressing the switch in HA e.g. it acutally does turn on or off when you press?
When you say it reverts to previous state if you leave it does it then change again to the correct state?

from sector.

MrDuco avatar MrDuco commented on September 26, 2024

Yes the plug works so it does really turn on or off when I click the switch in HA.
Switch in HA UI after reboot (On):
image

The plug (On), correct!
image

Then I turn it "Off" in UI:
image

And the plug goes to turns "Off", correct
image

So far everything is working as expected!

But then after a few seconds, switch in UI reverts to previous state, in this case "On"
image

But the plug is still "Off"
image

And waiting, (10 minutes now), refreshing or changing tabs in HA does not update the state either, only way to get switch and plug in sync again is to restart server.

from sector.

gjohansson-ST avatar gjohansson-ST commented on September 26, 2024

Very strange.
Can you turn on debug on sector component and check the log (doing same as above). You should see a line starting with "self._switchdata =" where it should say the output from sector api. Especially interesting to see this when it's out of sync.

from sector.

MrDuco avatar MrDuco commented on September 26, 2024

Ok, I think I manged to get it. Attached is full log also.

But in short it looks like this

Start up:
2021-12-15 15:10:00 DEBUG (MainThread) [custom_components.sector] self._switchdata = [{'Consumption': '-1', 'DisplayScenarios': False, 'Id': 'X', 'Label': 'Hallen nere', 'PanelId': None, 'SerialNo': 'X', 'Scenarios': None, 'Status': 'Off', 'TimerActive': False, 'TimerEvents': None, 'TimerEventsSchedule': None}, {'Consumption': '0', 'DisplayScenarios': False, 'Id': 'Y', 'Label': 'Köket', 'PanelId': None, 'SerialNo': 'Y', 'Scenarios': None, 'Status': 'On', 'TimerActive': False, 'TimerEvents': None, 'TimerEventsSchedule': None}, {'Consumption': '2', 'DisplayScenarios': False, 'Id': 'Z', 'Label': 'Vardagsrum', 'PanelId': None, 'SerialNo': 'Z', 'Scenarios': None, 'Status': 'On', 'TimerActive': False, 'TimerEvents': None, 'TimerEventsSchedule': None}]

Then when I click in UI to swtich:
2021-12-15 15:10:35 DEBUG (MainThread) [custom_components.sector] self._switchdata = [{'Consumption': '-1', 'DisplayScenarios': False, 'Id': 'X', 'Label': 'Hallen nere', 'PanelId': None, 'SerialNo': 'X', 'Scenarios': None, 'Status': 'Off', 'TimerActive': False, 'TimerEvents': None, 'TimerEventsSchedule': None}, {'Consumption': '-1', 'DisplayScenarios': False, 'Id': 'Y', 'Label': 'Köket', 'PanelId': None, 'SerialNo': 'Y', 'Scenarios': None, 'Status': 'Off', 'TimerActive': False, 'TimerEvents': None, 'TimerEventsSchedule': None}, {'Consumption': '2', 'DisplayScenarios': False, 'Id': 'Z', 'Label': 'Vardagsrum', 'PanelId': None, 'SerialNo': 'Z', 'Scenarios': None, 'Status': 'On', 'TimerActive': False, 'TimerEvents': None, 'TimerEventsSchedule': None}]

And then after 1 minute:
2021-12-15 15:10:41 DEBUG (MainThread) [custom_components.sector] self._switchdata = [{'Consumption': '-1', 'DisplayScenarios': False, 'Id': 'X', 'Label': 'Hallen nere', 'PanelId': None, 'SerialNo': 'X', 'Scenarios': None, 'Status': 'Off', 'TimerActive': False, 'TimerEvents': None, 'TimerEventsSchedule': None}, {'Consumption': '-1', 'DisplayScenarios': False, 'Id': 'Y', 'Label': 'Köket', 'PanelId': None, 'SerialNo': 'Y', 'Scenarios': None, 'Status': 'Off', 'TimerActive': False, 'TimerEvents': None, 'TimerEventsSchedule': None}, {'Consumption': '2', 'DisplayScenarios': False, 'Id': 'Z', 'Label': 'Vardagsrum', 'PanelId': None, 'SerialNo': 'Z', 'Scenarios': None, 'Status': 'On', 'TimerActive': False, 'TimerEvents': None, 'TimerEventsSchedule': None}]

debug_log.txt

from sector.

gjohansson-ST avatar gjohansson-ST commented on September 26, 2024

Can you confirm id and serialno is different on the three different plugs you have (since you masked it)?

from sector.

MrDuco avatar MrDuco commented on September 26, 2024

yes all are different.
were in the code should it update the switch state?
I get that it uses the API to fetch it from sector web page, but when is it set/updated on the entity?

from sector.

cttime avatar cttime commented on September 26, 2024

Yes the plug works so it does really turn on or off when I click the switch in HA. Switch in HA UI after reboot (On): image

The plug (On), correct! image

Then I turn it "Off" in UI: image

And the plug goes to turns "Off", correct image

So far everything is working as expected!

But then after a few seconds, switch in UI reverts to previous state, in this case "On" image

But the plug is still "Off" image

And waiting, (10 minutes now), refreshing or changing tabs in HA does not update the state either, only way to get switch and plug in sync again is to restart server.

If you look at MrDuco'first screenshot you can see the switch is on without any gray highlight (see photo 3 "off"). I see the same issue that the status doesn't change. A button card will not turn the switch on or off (usually) but if I go into the device page I can select on or off. Before the status will update (and allow a change again) I must click somewhere away from the switch so that the gray around the switch disappears. Once I have done this the status will update and I can change the switch once again.
If I do not click away from the gray highlighted switch it will do as MrDuco suggests and revert to the previous state status (but remain in the opposite position).

from sector.

gjohansson-ST avatar gjohansson-ST commented on September 26, 2024

Hi guys
Do think it's now sorted in the beta I just made. Give it a try and report back.

from sector.

MrDuco avatar MrDuco commented on September 26, 2024

I have done some testing and from what I can see it now seems to work as expected!
@gjohansson-ST - excellent work! thanks!

from sector.

gjohansson-ST avatar gjohansson-ST commented on September 26, 2024

I have done some testing and from what I can see it now seems to work as expected! @gjohansson-ST - excellent work! thanks!

Let's keep the beta for some days so we see everything works as expected. I can post a new proper release between Christmas and New year if I don't hear anything from you.

from sector.

gjohansson-ST avatar gjohansson-ST commented on September 26, 2024

Solved in latest release v0.3.4

from sector.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.