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 Compit integration #132164

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

Conversation

Przemko92
Copy link

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.

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 @Przemko92

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

home-assistant bot commented Dec 3, 2024

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.

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.

Copy link
Contributor

@abmantis abmantis left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!
Please limit this PR to a single platform, and add the others in follow-up PRs.

https://developers.home-assistant.io/docs/creating_component_code_review#5-make-your-pull-request-as-small-as-possible

CODEOWNERS Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft December 3, 2024 22:32
@Przemko92 Przemko92 marked this pull request as ready for review December 4, 2024 08:38
@home-assistant home-assistant bot requested a review from abmantis December 4, 2024 08:38
abmantis

This comment was marked as resolved.

@home-assistant home-assistant bot marked this pull request as draft December 4, 2024 10:33
@Przemko92 Przemko92 marked this pull request as ready for review December 4, 2024 11:45
@home-assistant home-assistant bot requested a review from abmantis December 4, 2024 11:45
homeassistant/components/compit/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/compit/manifest.json Outdated Show resolved Hide resolved
homeassistant/components/compit/manifest.json Outdated Show resolved Hide resolved
homeassistant/components/compit/manifest.json Outdated Show resolved Hide resolved
homeassistant/components/compit/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/compit/coordinator.py Outdated Show resolved Hide resolved
device.device_class,
device.type,
)
state = await self.api.get_state(device.id)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not strictly necessary, but we could have a get_devices() method on the library that returns the updated list of DeviceInstance (with state updated).
That way we could make the logic simpler here.

Copy link
Author

Choose a reason for hiding this comment

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

I will refactor it in the future releases

homeassistant/components/compit/manifest.json Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft December 9, 2024 12:26
@Przemko92 Przemko92 marked this pull request as ready for review December 11, 2024 20:24
@home-assistant home-assistant bot requested a review from abmantis December 11, 2024 20:24
homeassistant/components/compit/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/compit/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/compit/__init__.py Show resolved Hide resolved
homeassistant/components/compit/__init__.py Show resolved Hide resolved
homeassistant/components/compit/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/compit/climate.py Outdated Show resolved Hide resolved
homeassistant/components/compit/climate.py Outdated Show resolved Hide resolved
homeassistant/components/compit/climate.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft December 12, 2024 15:12
@Przemko92 Przemko92 marked this pull request as ready for review December 27, 2024 12:02
@home-assistant home-assistant bot requested a review from abmantis December 27, 2024 12:02
)
except ValueError as e:
_LOGGER.warning("Value error: %s", e)
return False
Copy link
Contributor

Choose a reason for hiding this comment

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

return True

_LOGGER.error("Authentication API error")
return False
Copy link
Contributor

Choose a reason for hiding this comment

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

raise ConfigEntryError instead

def current_temperature(self) -> float | None:
"""Return the current temperature."""
value = self.coordinator.data[self.device.id].state.get_parameter_value(
"__tpokojowa"
Copy link
Contributor

Choose a reason for hiding this comment

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

can we move this to a const instead? same for the other parameters

device.type,
)
continue
self.devices[device.id] = DeviceInstance(device_definition)
Copy link
Contributor

Choose a reason for hiding this comment

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

lets rename devices to device_instances or something, because otherwise it looks like it contains the actual devices instead of definitions

self._hvac_mode = None

@property
def device_info(self) -> DeviceInfo | None:
Copy link
Contributor

Choose a reason for hiding this comment

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

since all the data is available on __init__ you can define _attr_device_info instead.

self._attr_name = device.label
self._attr_has_entity_name = True
self._attr_temperature_unit = UnitOfTemperature.CELSIUS
self.parameters = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
self.parameters = {
parameters = {

no need to store it as an instance variable

"identifiers": {(DOMAIN, str(self.device.id))},
"name": self.device.label,
"manufacturer": MANURFACER_NAME,
"model": self.device_name,
Copy link
Contributor

Choose a reason for hiding this comment

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

if you define _attr_device_info you can remove device_name from the class

return [HVACMode.HEAT, HVACMode.COOL, HVACMode.OFF]

@property
def preset_mode(self) -> str | None:
Copy link
Contributor

Choose a reason for hiding this comment

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

can we cache the preset_mode, or does it change even if self._preset_mode remains?

Copy link
Contributor

@abmantis abmantis Dec 31, 2024

Choose a reason for hiding this comment

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

couldn't we just read/write _attr_preset_mode and avoid storing _preset_mode?

self._hvac_mode: HVACMode | None = None
self.set_initial_values()

def set_initial_values(self) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

since this is only called initially, how are the modes updated if a change is made from compit side and not from HA?

@home-assistant home-assistant bot marked this pull request as draft December 31, 2024 12:53
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