Skip to content

Commit

Permalink
update teh unit of mesurements
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinebou12 committed Mar 1, 2024
1 parent 158c5e0 commit 5550d4d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 6 additions & 0 deletions custom_components/renpho/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
CONF_PASSWORD,
CONF_PUBLIC_KEY,
CONF_REFRESH,
CONF_UNIT_OF_MEASUREMENT,
CONF_USER_ID,
DOMAIN,
EVENT_HOMEASSISTANT_STOP,
Expand Down Expand Up @@ -55,11 +56,16 @@ async def setup_renpho(hass, conf):
"""Common setup logic for YAML and UI."""
email = conf[CONF_EMAIL]
password = conf[CONF_PASSWORD]
unit_of_measurement = conf.get(CONF_UNIT_OF_MEASUREMENT, "kg")
user_id = conf.get(CONF_USER_ID, None)
refresh = conf.get(CONF_REFRESH, 600)
renpho = RenphoWeight(CONF_PUBLIC_KEY, email, password, user_id, refresh)
await renpho.get_info()
hass.data[DOMAIN] = renpho
hass.data[CONF_EMAIL] = email
hass.data[CONF_USER_ID] = user_id
hass.data[CONF_REFRESH] = refresh
hass.data[CONF_UNIT_OF_MEASUREMENT] = unit_of_measurement


async def async_prepare(hass, renpho, refresh):
Expand Down
7 changes: 3 additions & 4 deletions custom_components/renpho/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def sensors_list(
) -> list[RenphoSensor]:
"""Return a list of sensors."""
return [
RenphoSensor(hass.data[DOMAIN], **sensor, config_entry=config_entry)
RenphoSensor(hass.data[DOMAIN], **sensor, config_entry=config_entry, unit_of_measurement=hass[CONF_UNIT_OF_MEASUREMENT])
for sensor in sensor_configurations
]

Expand Down Expand Up @@ -77,6 +77,7 @@ def __init__(
label: str,
metric: str,
config_entry: ConfigEntry,
unit_of_measurement: str,
) -> None:
"""Initialize the sensor."""
self._renpho = renpho
Expand All @@ -86,9 +87,7 @@ def __init__(
self._unit = unit
self._category = category
self._label = label
self._unit_of_measurement = hass.data[DOMAIN]
CONF_UNIT_OF_MEASUREMENT, MASS_KILOGRAMS
)
self._unit_of_measurement = unit_of_measurement
self._timestamp = None
self._state = None

Expand Down

0 comments on commit 5550d4d

Please sign in to comment.