Add binary sensor platform to devolo Home Network#60301
Add binary sensor platform to devolo Home Network#60301bdraco merged 12 commits intohome-assistant:devfrom
Conversation
|
Hey there @2Fake, mind taking a look at this pull request as it has been labeled with an integration ( |
epenet
left a comment
There was a problem hiding this comment.
I think that you can improve the use of EntityDescription to have only a single DevoloBinarySensorEntity class.
To do this, you can create two module function _is_on_basic and _is_on_extended which take the entity as parameter, and you set value_func to the new module function accordingly.
|
Hi @epenet , thanks for the hint. It just didn't come to my mind to use the complete entity as parameter ... |
|
|
||
| self._device = device | ||
| self._device_name = device_name | ||
| self.device = device | ||
| self.device_name = device_name | ||
|
|
||
| self._attr_device_info = DeviceInfo( | ||
| configuration_url=f"http://{self._device.ip}", | ||
| identifiers={(DOMAIN, str(self._device.serial_number))}, | ||
| configuration_url=f"http://{self.device.ip}", | ||
| identifiers={(DOMAIN, str(self.device.serial_number))}, | ||
| manufacturer="devolo", | ||
| model=self._device.product, | ||
| name=self._device_name, | ||
| sw_version=self._device.firmware_version, | ||
| model=self.device.product, | ||
| name=self.device_name, | ||
| sw_version=self.device.firmware_version, | ||
| ) | ||
| self._attr_unique_id = ( | ||
| f"{self._device.serial_number}_{self.entity_description.key}" | ||
| f"{self.device.serial_number}_{self.entity_description.key}" | ||
| ) |
There was a problem hiding this comment.
I access device in _is_connected_to_router and with _ pylint complains about the private access.
There was a problem hiding this comment.
Since this is all in __init__, you could simply use device and device_name function arguments instead of self.xxx
There was a problem hiding this comment.
hmm, I'm not seeing it. Could you help me out? The signatures of _is_connected_to_router and the lambda (and any possible upcoming sensor) would need to be the same although _is_connected_to_router is most likely the only one needing it and having the information available inside the entity, right? Isn't then accessing entity.device (and by that making it public) cleaner?
There was a problem hiding this comment.
You keep the change at the top (lines 24/25):
self.device = device
self.device_name = device_nameBut in the subsequent lines instead of replacing self._dev... by self.dev... you replace it by dev... (drop the self._)
There was a problem hiding this comment.
Got it! I was at a complete different spot in the code ...
602e291 to
e7d8134
Compare
|
|
||
| # Emulate device failure | ||
| with patch( | ||
| "devolo_plc_api.plcnet_api.plcnetapi.PlcNetApi.async_get_network_overview", |
There was a problem hiding this comment.
| "devolo_plc_api.plcnet_api.plcnetapi.PlcNetApi.async_get_network_overview", | |
| "homeassistant.components.devolo_home_network.devolo_plc_api.plcnet_api.plcnetapi.PlcNetApi.async_get_network_overview", |
Usually we patch where the library is imported so we don't accidentally patch places we don't want to change
There was a problem hiding this comment.
In this case it would probably be better to adjust the mock_device instead
There was a problem hiding this comment.
The mock_device is just a collection of patches itself. I'm not seeing, how I could adjust it.
|
|
||
| # Emulate device failure | ||
| with patch( | ||
| "devolo_plc_api.device_api.deviceapi.DeviceApi.async_check_firmware_available", |
There was a problem hiding this comment.
Can you adjust mock_device instead of patching here?
| # Emulate state change | ||
| with patch( | ||
| "devolo_plc_api.device_api.deviceapi.DeviceApi.async_check_firmware_available", | ||
| new=AsyncMock(return_value={"result": "UPDATE_AVAILABLE"}), |
There was a problem hiding this comment.
Can you adjust mock_device instead of patching here?
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
|
not stale, awaits response (Didn't see the question until now) |
|
I guess, I should remove the firmware_update_available binary sensor, as update is an own platform by now, right? |
de11973 to
e52ab0f
Compare
|
Hi @bdraco , I removed the update sensor, so I guess I'm ready for review. |
Proposed change
Add binary sensor platform to devolo Home Network, starting with two entities: Firmware update and if the device is connected directly to the router. As the state of the later cannot be retrieved only from the coordinator, I implemented if differently than the other binary sensor and the existing sensors.
Type of change
Additional information
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: