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

Add IoTMeter integration #120087

Draft
wants to merge 31 commits into
base: dev
Choose a base branch
from
Draft

Add IoTMeter integration #120087

wants to merge 31 commits into from

Conversation

lipic
Copy link

@lipic lipic commented Jun 21, 2024

Breaking change

Proposed change

Type of change

  • Dependency upgrade
  • 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

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • 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.

To help with the load of incoming pull requests:

Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

Hi @lipic

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant home-assistant bot marked this pull request as draft June 21, 2024 11:26
Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

@lipic lipic marked this pull request as ready for review June 21, 2024 11:51
@home-assistant home-assistant bot dismissed stale reviews from themself June 21, 2024 11:51

Stale

@TheJulianJES TheJulianJES changed the title Added IoTMeter component Add IoTMeter integration Jun 21, 2024
Copy link
Member

@TheJulianJES TheJulianJES left a comment

Choose a reason for hiding this comment

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

CI is failing. Please take a look.
There's some guidance on the HA developer page for how to set up a HA dev environment. That way, you don't need to wait for GitHub CI to pass and can fix most/all errors locally.

Please also edit your PR description to add some further information about this.

@home-assistant home-assistant bot marked this pull request as draft June 21, 2024 12:06
Copy link
Member

@TheJulianJES TheJulianJES left a comment

Choose a reason for hiding this comment

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

From a quick look, icons belong in https://github.com/home-assistant/brands/ and we limit new integrations to one platform (sensor, number, ..) at first to make the review easier. Other platforms can be added in subsequent PRs.

@TheJulianJES TheJulianJES mentioned this pull request Jun 21, 2024
20 tasks
@lipic lipic marked this pull request as ready for review June 22, 2024 07:13
@joostlek
Copy link
Member

Not all comments are resolved, please resolve them before marking ready for review again

@joostlek joostlek marked this pull request as draft June 22, 2024 12:35
@lipic
Copy link
Author

lipic commented Jun 23, 2024

Not all comments are resolved, please resolve them before marking ready for review again

Could you please tell me what else needs to be done? Based on the comment, I may have corrected everything.

@lipic
Copy link
Author

lipic commented Jul 24, 2024

No you only removed the variable from the list, you didn't actually remove the platform

I thought that after deleting it from the list, the platform would not initialize and that this would be sufficient. To fix this, do I need to delete the number.py file?

@joostlek
Copy link
Member

Yes, we don't want loose pieces of code

@lipic
Copy link
Author

lipic commented Jul 24, 2024

Yes, we don't want loose pieces of code

Thanks for the advice. I have made the changes; should I update the branch?

"dependencies": [],
"documentation": "https://www.home-assistant.io/integrations/iotmeter",
"iot_class": "local_polling",
"requirements": ["aiohttp==3.9.5"]
Copy link
Member

Choose a reason for hiding this comment

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

The logic to connect to the device should be encapsulated in a package published on PyPi.

Copy link
Author

Choose a reason for hiding this comment

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

The logic to connect to the device should be encapsulated in a package published on PyPi.

Can I simply remove the requirements from manifest.json and use the aiohttp==3.10.0b1 version that is already a dependency in Home Assistant?

Copy link
Member

Choose a reason for hiding this comment

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

No, you need to create your own library with all the calls to the device/service and publish that to Pypi and use that

@home-assistant home-assistant bot marked this pull request as draft July 24, 2024 11:03
@lipic lipic marked this pull request as ready for review August 15, 2024 07:12
@home-assistant home-assistant bot requested a review from joostlek August 15, 2024 07:12
Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

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

Please make sure you are using a development environment to develop the integration, there are things in here that should have been caught by the pre-commit rules

@home-assistant home-assistant bot marked this pull request as draft August 15, 2024 08:23
@lipic
Copy link
Author

lipic commented Aug 15, 2024

Please make sure you are using a development environment to develop the integration, there are things in here that should have been caught by the pre-commit rules

"I'm sorry, I forgot to include the modified tests that were causing the error."

@joostlek
Copy link
Member

Who is vase-uzivatelske-jmeno?

@lipic
Copy link
Author

lipic commented Aug 15, 2024

Who is vase-uzivatelske-jmeno?

"My mistake, it should be @lipic. I will fix it."

@lipic lipic marked this pull request as ready for review August 15, 2024 11:17
@home-assistant home-assistant bot requested a review from joostlek August 15, 2024 11:17
homeassistant/components/iotmeter/__init__.py Show resolved Hide resolved
_LOGGER = logging.getLogger(__name__)
_LOGGER.setLevel(logging.DEBUG)

PLATFORMS = [Platform.SENSOR] # Platform.NUMBER
Copy link
Member

Choose a reason for hiding this comment

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

Why the comment


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up IoTMeter from a config entry."""
_LOGGER.debug("Setting up IoTMeter integration")
Copy link
Member

Choose a reason for hiding this comment

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

Not needed

Comment on lines +21 to +22
if DOMAIN not in hass.data:
hass.data[DOMAIN] = {} # Ensure that the domain is a dictionary
Copy link
Member

Choose a reason for hiding this comment

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

Please use entry.runtime_data. Check airgradient for an example. You should extend the ConfigEntry type with the type for the runtime_data.

Comment on lines +24 to +25
ip_address = entry.data.get("ip_address")
port = entry.data.get("port", 8000) # Default to port 8000 if not set
Copy link
Member

Choose a reason for hiding this comment

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

Use constants

self.total_power: float = 0

@property
def state(self):
Copy link
Member

Choose a reason for hiding this comment

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

Don't use state

Comment on lines +62 to +66
p1 = (
self.coordinator.data.get("P1") - 65535
if self.coordinator.data.get("P1") > 32767
else self.coordinator.data.get("P1")
)
Copy link
Member

Choose a reason for hiding this comment

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

This is device specific, please move to the library

Comment on lines +77 to +80
if p1 is not None and p2 is not None and p3 is not None:
self.total_power = (float(p1) + float(p2) + float(p3)) / 1000
return round(self.total_power, 2)
return None
Copy link
Member

Choose a reason for hiding this comment

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

This is an abstraction, we want to provide the device to HA as raw as possible

return None

@property
def extra_state_attributes(self):
Copy link
Member

Choose a reason for hiding this comment

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

Don't add extra state attributes

Comment on lines +13 to +34
@pytest.fixture
def mock_config_flow(hass):
"""Fixture for creating a config flow instance."""
flow = EVConfigFlow()
flow.hass = hass
return flow


@pytest.fixture
async def hass(tmpdir):
"""Fixture for Home Assistant instance."""
hass = HomeAssistant(tmpdir)
hass.config_entries = config_entries.ConfigEntries(
hass, {}
) # Initialize config_entries with an empty config

await hass.async_start()
await hass.async_block_till_done()
hass.data["integrations"] = {} # Initialize the 'integrations' key

yield hass
await hass.async_stop()
Copy link
Member

Choose a reason for hiding this comment

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

Euh, why? Please check other integrations for how they do their config flow tests

@home-assistant home-assistant bot marked this pull request as draft August 21, 2024 13:39
@lipic lipic marked this pull request as ready for review August 21, 2024 13:59
@home-assistant home-assistant bot requested a review from joostlek August 21, 2024 13:59
@joostlek joostlek marked this pull request as draft August 21, 2024 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants