Skip to content
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

Example support for Burze.dzis.net v2.0.0 #203

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

PiotrMachowski
Copy link

@PiotrMachowski PiotrMachowski commented Jul 16, 2023

Hi, I have made this short example how you can add support for Burze.dzis.net v2.0.0+ to your card.

Fixes #201

@PiotrMachowski
Copy link
Author

Approach used in this PR can also handle changed entity ids:
image

Copy link
Owner

@MrBartusek MrBartusek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! Thank you for this extensive PR! Detecting event type by unique_id is a great idea and the project will benefit from allowing integration methods to be asynchronous. I was not able to test it yet since there are no warnings today but, I've made a dry review for now.

Comment on lines +30 to +32
supports(hass: HomeAssistant, entity: HassEntity): Promise<boolean>,
alertActive(entity: HassEntity): boolean,
getAlerts(entity: HassEntity): MeteoalarmAlert[] | MeteoalarmAlert,
getAlerts(hass: HomeAssistant, entity: HassEntity): Promise<MeteoalarmAlert[]> | Promise<MeteoalarmAlert>,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like what you did here with passing hass object with each supports and getAlerts call. It just brings more clutter to these function calls. The better approach here might be passing hass object with the integration constructor and then storing it in the integration object

@@ -27,9 +27,9 @@ export interface MeteoalarmCardConfig extends LovelaceCardConfig {

export interface MeteoalarmIntegration {
metadata: MeteoalarmIntegrationMetadata,
supports(entity: HassEntity): boolean,
supports(hass: HomeAssistant, entity: HassEntity): Promise<boolean>,
alertActive(entity: HassEntity): boolean,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that you have moved all integration methods to be async but you can also do that alertActive It doesn't make sense that every method except this one is asynchronous

Comment on lines +133 to +139
export type EntityRegistryEntry = {
entity_id: string;
original_icon: string;
icon?: string;
unique_id: string;
disabled_by?: string;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can map these snake_case varables into camelCase ones

Comment on lines +60 to +65
public static async getEntityInfo(hass: HomeAssistant, entity: HassEntity): Promise<EntityRegistryEntry> {
return await hass.callWS<EntityRegistryEntry>({
type: 'config/entity_registry/get',
entity_id: entity.entity_id
});
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add jsdoc comment here this function looks extremely confiusing

@@ -71,7 +78,7 @@ export class MeteoalarmCard extends LitElement {
ALLOWED_INTEGRATION_TYPES.includes(x.metadata.type)
);
for(const integration of integrations) {
if(integration.supports(hass.states[entity])) {
if(await integration.supports(hass, hass.states[entity])) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For code style, move all of these to be such as such:

const supports = await integration.supports(hass, hass.states[entity];
if(supports) {
	...
}

@PiotrMachowski
Copy link
Author

This PR has been made mostly as a way of showing how the problem can be solved, not as an actual final solution - it was put together in a few hours as a proof of concept.

Potential improvements and checks that need to be performed:

  • I'm not 100% sure it is able to handle changing state of a sensor without refreshing page
  • Configuration can be stored in the memory in setConfig method to avoid making unnecessary calls to API during render phase (this data doesn't change; this will make scheduleUpdate method unnecessary)
  • I haven't tested if other integrations still work

To test if the card displays data correctly you can set coordinates to (0, 0) (manually, by editing core.config_entries file in .storage). You should be able to test if the card is refreshed correctly by changing a state of entities in dev tools.

@MrBartusek
Copy link
Owner

This PR has been made mostly as a way of showing how the problem can be solved, not as an actual final solution - it was put together in a few hours as a proof of concept.

So this is not the solution and you don't want to work on it?

@PiotrMachowski
Copy link
Author

It can be treated as a starting point on a way to get a final solution. I can work on it, but unfortunately not at this moment, so you can take over development if you want to make it work sooner.

@PiotrMachowski
Copy link
Author

Just to clarify; should I put it on my TODO list or do you want to take over development?

@MrBartusek
Copy link
Owner

Just to clarify; should I put it on my TODO list or do you want to take over development?

Honesty, i dont know when I will get to it so i would say yeah, put it there. leet me know when you work on this i will do the same, will see who gets it done first

@pskowronek
Copy link

pskowronek commented Mar 24, 2024

@PiotrMachowski & @MrBartusek any hope to have burze.dzis.net working in HA AD2024? :)

Either remove burze.dzis.net from MeteoalarmCard as a supported integration in readme.md, or move on with this PR :) it already hangs like 9 months, and windy times are coming to Poland :)
obraz

@nepozs
Copy link
Contributor

nepozs commented Jul 13, 2024

@pskowronek
Quick workaround is known from the day when incompatibility started
https://forum.arturhome.pl/t/integracja-burze-dzis-net-jak-wyswietlic-tylko-ostrzezenia-wlaczone/5189/10?u=szopen

@pskowronek
Copy link

@pskowronek Quick workaround is known from the day when incompatibility started https://forum.arturhome.pl/t/integracja-burze-dzis-net-jak-wyswietlic-tylko-ostrzezenia-wlaczone/5189/10?u=szopen

yup, I think this was the post that led me here to make a ping in this PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Entities from Burze.dzis.net sensor v2.0.0 incompatible with MeteoalarmCard
4 participants