-
Notifications
You must be signed in to change notification settings - Fork 582
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
Physical device #12
Physical device #12
Conversation
I don't really understand why you are adding And why are you storing the names inside the pytuya instance? IMHO a name field in the library should only exist if the library itself could provide the name, e.g. by asking the device. The name is already present via |
Ok, now I looked at it again and I see the problem. We can't do it like this, we need to manually set up a device in the device registry that corresponds to the actual hardware. We need link out entities using "via_device" in Setting up the device is done roughly like here: The "via_device" should not be there though. Each platform then link to this device like this: Sorry about the confusion here. Th device registry is still a bit new to me. Device name (we publish in the first step) is fetched from the config entry, I.e. |
Yes, probably since you have explained that the device_id can't be set from code probably it's better to remove the name attribute. |
OK so now it's time to clarify the names. In case of a smart plug, the device is the physical device (identified by the |
Yes, I think we are on the same page there. How I look at it, the physical device is a "hub" and the things it can control are the entities. This simply because none if the entities themselves can function without the physical device (hub) handling communication. From a logical POV each entity, e.g. switches, are independent. A double gang socket is presented as two switches in the UI with seemingly nothing in common, since they control two different things independently and the user might not even know that it's the same physical socket. How it's implemented is a different story and I agree, we should store the shared instance in |
What sounds strange to me using the via_device is that here: |
Moreover, I'd say next step is to get rid of TuyaCache, which is actually the wrapper for our Device. |
Lets take an example, again with double gang switch as that is an interesting case. We connect the fridge to one of the sockets and freezer to the other. The naming scheme could then be "Kitchen Home Appliances" for the physical device, "Fridge" for the entity connected to the fridge and "Freezer" for the entity connected to the... freezer. I would expect three "devices" for this in Home Assistant with the mentioned names. The physical device would have I think you still left a small bug in your revert, because you pass name of the integration into the |
Ooops, right. fixing it. Mmm, here is where I don't agree much, or maybe I am not getting it. I would just expect 1 device, and 2 entities, not 3 devices.
|
One problem is that the "device" you see comes from the switches. What does the information you see even mean here? What if you were to return different firmware versions or models for each switch, then what happens? Or if you add entities with other platforms? Is it still a "SmartSwitch"? I believe the UI will still call it an entity even if it is implemented as a device, but I can be wrong. The upside of having devices is that you can use device automations. I'll look around to see if I can find any examples of what other people have done. |
I have another interesting use case: my cover. It has 1 cover, and 1 switch actually (the backlight). |
It would not be the responsibility of the platform to set that up, we would have to move that into the component instead ( Yeah, I will try to figure something out. But what we are doing know isn't really correct IMHO at least. |
Merges #6 and #11.
Moreover, introduces the creation of Devices under Configuration-Devices, regrouping related subswitches.