Skip to content

Commit

Permalink
Merge pull request #135 from deluge/bugfix/get-state
Browse files Browse the repository at this point in the history
Fix reading state value
  • Loading branch information
Olen authored Jan 29, 2024
2 parents da948b0 + 166bc36 commit 2bf0d1b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 13 deletions.
23 changes: 16 additions & 7 deletions custom_components/plant/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for monitoring plants."""

from __future__ import annotations

import logging
Expand Down Expand Up @@ -629,7 +630,9 @@ def update(self) -> None:
known_state = False

if self.sensor_moisture is not None:
moisture = self._hass.states.get(self.sensor_moisture.entity_id).state
moisture = getattr(
self._hass.states.get(self.sensor_moisture.entity_id), "state", None
)
if (
moisture is not None
and moisture != STATE_UNKNOWN
Expand All @@ -648,9 +651,9 @@ def update(self) -> None:
self.moisture_status = STATE_OK

if self.sensor_conductivity is not None:
conductivity = self._hass.states.get(
self.sensor_conductivity.entity_id
).state
conductivity = getattr(
self._hass.states.get(self.sensor_conductivity.entity_id), "state", None
)
if (
conductivity is not None
and conductivity != STATE_UNKNOWN
Expand All @@ -669,7 +672,9 @@ def update(self) -> None:
self.conductivity_status = STATE_OK

if self.sensor_temperature is not None:
temperature = self._hass.states.get(self.sensor_temperature.entity_id).state
temperature = getattr(
self._hass.states.get(self.sensor_temperature.entity_id), "state", None
)
if (
temperature is not None
and temperature != STATE_UNKNOWN
Expand All @@ -688,7 +693,9 @@ def update(self) -> None:
self.temperature_status = STATE_OK

if self.sensor_humidity is not None:
humidity = self._hass.states.get(self.sensor_humidity.entity_id).state
humidity = getattr(
self._hass.states.get(self.sensor_humidity.entity_id), "state", None
)
if (
humidity is not None
and humidity != STATE_UNKNOWN
Expand All @@ -709,7 +716,9 @@ def update(self) -> None:
# Check the instant values for illuminance against "max"
# Ignoring "min" value for illuminance as it would probably trigger every night
if self.sensor_illuminance is not None:
illuminance = self._hass.states.get(self.sensor_illuminance.entity_id).state
illuminance = getattr(
self._hass.states.get(self.sensor_illuminance.entity_id), "state", None
)
if (
illuminance is not None
and illuminance != STATE_UNKNOWN
Expand Down
13 changes: 7 additions & 6 deletions custom_components/plant/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Config flow for Custom Plant integration."""

from __future__ import annotations

import logging
Expand Down Expand Up @@ -467,9 +468,9 @@ async def async_step_init(
)
] = cv.string
if plant_helper.has_openplantbook and self.plant.species:
data_schema[
vol.Optional(FLOW_FORCE_SPECIES_UPDATE, default=False)
] = cv.boolean
data_schema[vol.Optional(FLOW_FORCE_SPECIES_UPDATE, default=False)] = (
cv.boolean
)

display_species = self.plant.display_species or ""
data_schema[
Expand All @@ -489,9 +490,9 @@ async def async_step_init(
FLOW_ILLUMINANCE_TRIGGER, default=self.plant.illuminance_trigger
)
] = cv.boolean
data_schema[
vol.Optional(FLOW_DLI_TRIGGER, default=self.plant.dli_trigger)
] = cv.boolean
data_schema[vol.Optional(FLOW_DLI_TRIGGER, default=self.plant.dli_trigger)] = (
cv.boolean
)

data_schema[
vol.Optional(FLOW_HUMIDITY_TRIGGER, default=self.plant.humidity_trigger)
Expand Down
1 change: 1 addition & 0 deletions custom_components/plant/group.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Describe group states."""

from __future__ import annotations

from homeassistant.components.group import GroupIntegrationRegistry
Expand Down
1 change: 1 addition & 0 deletions custom_components/plant/number.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Max/Min threshold classes for the plant device"""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions custom_components/plant/plant_helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Helper functions for the plant integration"""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions custom_components/plant/plant_thresholds.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Max/Min threshold classes for the plant device"""

from __future__ import annotations

import logging
Expand Down

0 comments on commit 2bf0d1b

Please sign in to comment.