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

Fetch sensor data #10

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

puchupala
Copy link

Add temperature, humidity, and illuminance sensors as 3 new separate entities.

This is my first time playing around with Home Assistant so I'm not sure how efficient my code is.
Most of the code is a direct modification from the Nature Remo E sensor.
Specifically, I'm not sure why we need the following method.

async def async_added_to_hass(self):
    """Subscribe to updates."""
    self.async_on_remove(
        self._coordinator.async_add_listener(self.async_write_ha_state)
    )

In any case, things seem to work...

@calee0219
Copy link

Hi,

I've try this PR but I meet the error as below:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 383, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 588, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 615, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 368, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 402, in _async_write_ha_state
    state = self._stringify_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 374, in _stringify_state
    state = self.state
  File "/config/custom_components/nature_remo/sensor.py", line 134, in state
    return device["newest_events"]["hu"]["val"]
KeyError: 'hu'

@puchupala
Copy link
Author

@calee0219 Thank you very much for the report. I developed this PR for Nature Remo 3 which has temperature, humidity, illumination, and motion sensors.

I guess you test this PR with Nature Remo Mini, which only has a temperature sensor. Is this correct?

I will make the change to check for the availability of each sensor instead of just assuming that all sensors are available.

@calee0219
Copy link

Yes, the controler is using Nature Remo and Nature Remo Mini both.

@puchupala
Copy link
Author

@calee0219 It's a very small change so I haven't really tested the code. Would you please confirm whether the latest commit fixes the issue?

@calee0219
Copy link

@puchupala thanks a lot! I have check on my side and there is no error now!

Copy link

@calee0219 calee0219 left a comment

Choose a reason for hiding this comment

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

The PR work on my environment.

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.

2 participants