Repository: home-assistant/core
Pull request: Bump aioswitcher to 3.4.1
Bump aioswitcher to 3.4.1

GitHub diff: https://github.com/TomerFi/aioswitcher/compare/3.3.0...3.4.1
Release notes: https://github.com/TomerFi/aioswitcher/releases/tag/3.4.1

<!--
  You are amazing! Thanks for contributing to our project!
  Please, DO NOT DELETE ANY TEXT from this template! (unless instructed).
-->
## Breaking change
<!--
  If your PR contains a breaking change for existing users, it is important
  to tell them what breaks, how to make it work again and why we did this.
  This piece of text is published with the release notes, so it helps if you
  write it towards our users, not us.
  Note: Remove this section if this PR is NOT a breaking change.
-->


## Proposed change
<!--
  Describe the big picture of your changes here to communicate to the
  maintainers why we should accept this pull request. If it fixes a bug
  or resolves a feature request, be sure to link to that issue in the
  additional information section.
-->


## Type of change
<!--
  What type of change does your PR introduce to Home Assistant?
  NOTE: Please, check only 1! box!
  If your PR requires multiple boxes to be checked, you'll most likely need to
  split it into multiple PRs. This makes things easier and faster to code review.
-->

- [x] Dependency upgrade
- [x] Bugfix (non-breaking change which fixes an issue)
- [ ] New integration (thank you!)
- [ ] New feature (which adds functionality to an existing integration)
- [ ] Deprecation (breaking change to happen in the future)
- [ ] Breaking change (fix/feature causing existing functionality to break)
- [ ] Code quality improvements to existing code or addition of tests

## Additional information
<!--
  Details are important, and help maintainers processing your PR.
  Please be sure to fill out additional details, if applicable.
-->

- This PR fixes or closes issue: fixes https://github.com/home-assistant/core/issues/100955
- This PR is related to issue: 
- Link to documentation pull request: 

## Checklist
<!--
  Put an `x` in the boxes that apply. You can also fill these out after
  creating the PR. If you're unsure about any of them, don't hesitate to ask.
  We're here to help! This is simply a reminder of what we are going to look
  for before merging your code.
-->

- [x] The code change is tested and works locally.
- [x] Local tests pass. **Your PR cannot be merged unless tests pass**
- [x] There is no commented out code in this PR.
- [x] I have followed the [development checklist][dev-checklist]
- [x] I have followed the [perfect PR recommendations][perfect-pr]
- [x] The code has been formatted using Ruff (`ruff format homeassistant tests`)
- [x] Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

- [ ] Documentation added/updated for [www.home-assistant.io][docs-repository]

If the code communicates with devices, web services, or third-party tools:

- [x] The [manifest file][manifest-docs] has all fields filled out correctly.  
      Updated and included derived files by running: `python3 -m script.hassfest`.
- [x] New or updated dependencies have been added to `requirements_all.txt`.  
      Updated by running `python3 -m script.gen_requirements_all`.
- [x] For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
- [ ] Untested files have been added to `.coveragerc`.

<!--
  This project is very active and we have a high turnover of pull requests.

  Unfortunately, the number of incoming pull requests is higher than what our
  reviewers can review and merge so there is a long backlog of pull requests
  waiting for review. You can help here!
  
  By reviewing another pull request, you will help raise the code quality of
  that pull request and the final review will be faster. This way the general
  pace of pull request reviews will go up and your wait time will go down.
  
  When picking a pull request to review, try to choose one that hasn't yet
  been reviewed.

  Thanks for helping out!
-->

To help with the load of incoming pull requests:

- [ ] I have reviewed two other [open pull requests][prs] in this repository.

[prs]: https://github.com/home-assistant/core/pulls?q=is%3Aopen+is%3Apr+-author%3A%40me+-draft%3Atrue+-label%3Awaiting-for-upstream+sort%3Acreated-desc+review%3Anone+-status%3Afailure

<!--
  Thank you for contributing <3

  Below, some useful links you could explore:
-->
[dev-checklist]: https://developers.home-assistant.io/docs/development_checklist/
[manifest-docs]: https://developers.home-assistant.io/docs/creating_integration_manifest/
[quality-scale]: https://developers.home-assistant.io/docs/integration_quality_scale_index/
[docs-repository]: https://github.com/home-assistant/home-assistant.io
[perfect-pr]: https://developers.home-assistant.io/docs/review-process/#creating-the-perfect-pr


Problem statement:
Switch not working
### The problem

Hello, 
every switcher that is installed does not work in Home Assistant. 
Tried removing the integration and the component from the Switcher app and reconnecting - doesn't work.

Log:
```
Call api for Socket Oven failed, api: 'control_device', args: (<Command.ON: '1'>,), response/error: SwitcherBaseResponse(unparsed_response=b'')
```

### What version of Home Assistant Core has the issue?

2023.9.3

### What was the last working version of Home Assistant Core?

_No response_

### What type of installation are you running?

Home Assistant Container

### Integration causing the issue

Switcher

### Link to integration documentation on our website

_No response_

### Diagnostics information

_No response_

### Example YAML snippet

_No response_

### Anything in the logs that might be useful for us?

_No response_

### Additional information

_No response_

Hints from issue discussion:
Hey there @thecode, mind taking a look at this issue as it has been labeled with an integration (`switcher_kis`) you are listed as a [code owner](https://github.com/home-assistant/core/blob/dev/CODEOWNERS#L1252) for? Thanks!

<details>
<summary>Code owner commands</summary>


Code owners of `switcher_kis` 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 switcher_kis` Removes the current integration label and assignees on the issue, add the integration domain after the command.

</details>


<sub><sup>(message by CodeOwnersMention)</sup></sub>

---

[switcher_kis documentation](https://www.home-assistant.io/integrations/switcher_kis)
[switcher_kis source](https://github.com/home-assistant/core/tree/dev/homeassistant/components/switcher_kis)
<sub><sup>(message by IssueLinks)</sup></sub>
This is related to the device FW, see:
https://github.com/home-assistant/core/issues/94872#issuecomment-1599346646

And a workaround here (step 3 & 6 are not needed):
https://github.com/home-assistant/core/issues/92269#issuecomment-1600372457

> This is related to the device FW, see: [#94872 (comment)](https://github.com/home-assistant/core/issues/94872#issuecomment-1599346646)
> 
> And a workaround here (step 3 & 6 are not needed): [#92269 (comment)](https://github.com/home-assistant/core/issues/92269#issuecomment-1600372457)

The current and latest version of the switcher socket is 5.09 and it doesn't work.
I ran into the same problem, the fix for me was disable 5Ghz WIFI network, connect the switcher device to 2.4Ghz fixed the problem and the Home Assistant integration quickly found the device.
Same problem, it looks like there is a problem with the switcher servers, maybe it is because a cyber attack 
Update:
Got it resolved by looking at similar questions on the HA group in FB.
1. Switch OG app to Local, and reopen the app
2. While app in Local, turn on the boiler and turn it off.
3. Disable Local in app.
4. Test HA - works.

I ran into the same problem (integration stopped working), but the suggested fix of re-adding the device didn't work for me. The device's Firmware is 5.15 and my HA Core is 2023.11.2
Switcher works just fine using its dedicated app, just not from HA. I can see its exact status in HA (on/off, power, etc), just not able to turn it on/off.
 
Like wise.
I can see the status of the switch, but can't control it.
That's the all point of a switch... to be able to SWITCH it.

Unfortunately, i wasn't aware when i bought it ):
I hope this will be resolved soon and that it's more of a software capability rather then HW limitation.
Same here, Same error
working with docker BTW,
Sometimes it works, sometimes it doesn't.
@idofl 's workaround worked for me. 
FYI
Same here :/

Call api for Switcher Touch failed, api: 'control_device', args: (<Command.ON: '1'>,), response/error: SwitcherBaseResponse(unparsed_response=b'')

Commit message: switcher: small fix

Patch to review:
diff --git a/homeassistant/components/switcher_kis/__init__.py b/homeassistant/components/switcher_kis/__init__.py
index fb6ded993467eb..aec6c6560a8d1b 100644
--- a/homeassistant/components/switcher_kis/__init__.py
+++ b/homeassistant/components/switcher_kis/__init__.py
@@ -89,8 +89,9 @@ def on_device_data_callback(device: SwitcherBase) -> None:
 
         # New device - create device
         _LOGGER.info(
-            "Discovered Switcher device - id: %s, name: %s, type: %s (%s)",
+            "Discovered Switcher device - id: %s, key: %s, name: %s, type: %s (%s)",
             device.device_id,
+            device.device_key,
             device.name,
             device.device_type.value,
             device.device_type.hex_rep,
@@ -157,6 +158,11 @@ def device_id(self) -> str:
         """Switcher device id."""
         return self.data.device_id  # type: ignore[no-any-return]
 
+    @property
+    def device_key(self) -> str:
+        """Switcher device key."""
+        return self.data.device_key  # type: ignore[no-any-return]
+
     @property
     def mac_address(self) -> str:
         """Switcher device mac address."""
diff --git a/homeassistant/components/switcher_kis/button.py b/homeassistant/components/switcher_kis/button.py
index 5a1b7c821d2758..e23605244f4b58 100644
--- a/homeassistant/components/switcher_kis/button.py
+++ b/homeassistant/components/switcher_kis/button.py
@@ -142,7 +142,7 @@ async def async_press(self) -> None:
 
         try:
             async with SwitcherType2Api(
-                self.coordinator.data.ip_address, self.coordinator.data.device_id
+                self.coordinator.data.ip_address, self.coordinator.data.device_id, self.coordinator.data.device_key
             ) as swapi:
                 response = await self.entity_description.press_fn(swapi, self._remote)
         except (asyncio.TimeoutError, OSError, RuntimeError) as err:
diff --git a/homeassistant/components/switcher_kis/climate.py b/homeassistant/components/switcher_kis/climate.py
index 809e3d6a3ad710..dd17b75b06bd93 100644
--- a/homeassistant/components/switcher_kis/climate.py
+++ b/homeassistant/components/switcher_kis/climate.py
@@ -162,7 +162,7 @@ async def _async_control_breeze_device(self, **kwargs: Any) -> None:
 
         try:
             async with SwitcherType2Api(
-                self.coordinator.data.ip_address, self.coordinator.data.device_id
+                self.coordinator.data.ip_address, self.coordinator.data.device_id, self.coordinator.data.device_key
             ) as swapi:
                 response = await swapi.control_breeze_device(self._remote, **kwargs)
         except (asyncio.TimeoutError, OSError, RuntimeError) as err:
diff --git a/homeassistant/components/switcher_kis/cover.py b/homeassistant/components/switcher_kis/cover.py
index c627f361d7dad8..925667e8941c24 100644
--- a/homeassistant/components/switcher_kis/cover.py
+++ b/homeassistant/components/switcher_kis/cover.py
@@ -98,7 +98,7 @@ async def _async_call_api(self, api: str, *args: Any) -> None:
 
         try:
             async with SwitcherType2Api(
-                self.coordinator.data.ip_address, self.coordinator.data.device_id
+                self.coordinator.data.ip_address, self.coordinator.data.device_id, self.coordinator.data.device_key
             ) as swapi:
                 response = await getattr(swapi, api)(*args)
         except (asyncio.TimeoutError, OSError, RuntimeError) as err:
diff --git a/homeassistant/components/switcher_kis/diagnostics.py b/homeassistant/components/switcher_kis/diagnostics.py
index 93b3c36bd21445..765a3dde9e728e 100644
--- a/homeassistant/components/switcher_kis/diagnostics.py
+++ b/homeassistant/components/switcher_kis/diagnostics.py
@@ -10,7 +10,7 @@
 
 from .const import DATA_DEVICE, DOMAIN
 
-TO_REDACT = {"device_id", "ip_address", "mac_address"}
+TO_REDACT = {"device_id", "device_key", "ip_address", "mac_address"}
 
 
 async def async_get_config_entry_diagnostics(
diff --git a/homeassistant/components/switcher_kis/manifest.json b/homeassistant/components/switcher_kis/manifest.json
index 9accda95912b6f..055c92cc2fa1bf 100644
--- a/homeassistant/components/switcher_kis/manifest.json
+++ b/homeassistant/components/switcher_kis/manifest.json
@@ -7,5 +7,5 @@
   "iot_class": "local_push",
   "loggers": ["aioswitcher"],
   "quality_scale": "platinum",
-  "requirements": ["aioswitcher==3.3.0"]
+  "requirements": ["aioswitcher==3.4.1"]
 }
diff --git a/homeassistant/components/switcher_kis/switch.py b/homeassistant/components/switcher_kis/switch.py
index ef8564b37700ad..e08ed59431f398 100644
--- a/homeassistant/components/switcher_kis/switch.py
+++ b/homeassistant/components/switcher_kis/switch.py
@@ -111,7 +111,7 @@ async def _async_call_api(self, api: str, *args: Any) -> None:
 
         try:
             async with SwitcherType1Api(
-                self.coordinator.data.ip_address, self.coordinator.data.device_id
+                self.coordinator.data.ip_address, self.coordinator.data.device_id, self.coordinator.data.device_key
             ) as swapi:
                 response = await getattr(swapi, api)(*args)
         except (asyncio.TimeoutError, OSError, RuntimeError) as err:
diff --git a/requirements_all.txt b/requirements_all.txt
index dbf6af74eaaef6..45a18853fa2e68 100644
--- a/requirements_all.txt
+++ b/requirements_all.txt
@@ -371,7 +371,7 @@ aioslimproto==2.3.3
 aiosteamist==0.3.2
 
 # homeassistant.components.switcher_kis
-aioswitcher==3.3.0
+aioswitcher==3.4.1
 
 # homeassistant.components.syncthing
 aiosyncthing==0.5.1
diff --git a/requirements_test_all.txt b/requirements_test_all.txt
index bfe06e514a6aab..7369d916aea8f1 100644
--- a/requirements_test_all.txt
+++ b/requirements_test_all.txt
@@ -344,7 +344,7 @@ aioslimproto==2.3.3
 aiosteamist==0.3.2
 
 # homeassistant.components.switcher_kis
-aioswitcher==3.3.0
+aioswitcher==3.4.1
 
 # homeassistant.components.syncthing
 aiosyncthing==0.5.1


Code review comments:
diff_hunk: @@ -157,6 +158,11 @@ def device_id(self) -> str:
         """Switcher device id."""
         return self.data.device_id  # type: ignore[no-any-return]
 
+    @property
+    def device_key(self) -> str:
+        """Switcher device key."""
+        return self.data.device_key  # type: ignore[no-any-return]
+
path: homeassistant/components/switcher_kis/__init__.py
text: @user1:
This is not used anywhere in the code, no need to add this property
```suggestion
```


@author:
It is used. for all the API calls.

@user1:
You use the `data` --> `self.coordinator.data.device_key`, this would be accesbile using `self.coordinator.device_key` which is not needed in this case.
Coordinator properties are used if the underling data needs to be processed and accessed in multiple places.

@author:
Not sure I got you.. How it's different to device_id?

@user1:
Try the remove the code as I suggested above and noticed that it is not used anywhere

@author:
it is done.