shannonhochkins/ha-component-kit

Extend entity types generator to include attributes too

Closed this issue · 6 comments

Right now, entity names are typed, but their mapping to domains doesn't include attributes that vary between integrations.
Because of that, attributes lack completion and validation.
If it was possible to pull the services from HA, can the same be done for attributes?
2023-08-25 at 17 23 40@2x

Yep! I have tried this before, home assistant doesn't provide certain attributes in certain states, ie if you have colortemp set on a light, the hscolor attribute isn't provided on the entity, so it's completely possible that the types could be missing properties but I'll do some digging

I have something in the works for the entity attributes, probably 80% there, however there's still a lot that even in home assistant, isnt typed, the calandar entities is one of them that isn't typed in the home assistant repository either

I will be providing a simple way to extend DomainEntities manually if need be as I can't predict all types from all domains as there's far too many of them, however the types I am generating are identical to home assistant dashboard and can be synced every time i publish

So far, I've been able to retrieve and generate types for the following Domains:

AlarmControlPanelEntity
AutomationEntity
CameraEntity
ClimateEntity
CoverEntity
FanEntity
GroupEntity
HumidifierEntity
ImageEntity
InputSelectEntity
LawnMowerEntity
LightEntity
LockEntity
MediaPlayerEntity
RemoteEntity
SceneEntity
ScriptEntity
SelectEntity
TextEntity
TimerEntity
UpdateEntity
VacuumEntity
WaterHeaterEntity
WeatherEntity

I still have a bit of testing to do, just providing you with an update, this means that whenever you use an entity, if it be from the useEntity hook, you'll receive the types from these entities rather than the generic HassEntityBase

For everything else as mentioned i'll provide a way to extend it but that's the best i can do!

Just released new versions of the package, including documentation on how to extend your own (at the bottom of this page)

PR - here's the PR for reference

Let me know how you go!

I do have another idea on how to handle the types from entities that aren't typed in the home assistant repository, I will play around with it but at least for now you have the option to add your own types 😉

I will close this one, if you have any further issues please open another ticket :)