Skip to content

Commit

Permalink
Merge pull request #11 from antoinebou12/master
Browse files Browse the repository at this point in the history
v2.0.0
  • Loading branch information
neilzilla committed Nov 12, 2023
2 parents cc86eb9 + b21b759 commit 3bf2148
Show file tree
Hide file tree
Showing 11 changed files with 1,360 additions and 317 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/antoinebou12/hass_renpho?color=41BDF5&style=for-the-badge)](https://github.com/antoinebou12/hass_renpho/releases/latest)
[![Integration Usage](https://img.shields.io/badge/dynamic/json?color=41BDF5&style=for-the-badge&logo=home-assistant&label=usage&suffix=%20installs&cacheSeconds=15600&url=https://analytics.home-assistant.io/custom_integrations.json&query=$.hass_renpho.total)](https://analytics.home-assistant.io/custom_integrations.json&query=$.hass_renpho.total)

USE V.1.0.0 Please
[![Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.](https://my.home-assistant.io/badges/hacs_repository.svg)](https://my.home-assistant.io/redirect/hacs_repository/?owner=antoinebou12&repository=hass_renpho&category=Integration)

## Overview

Expand All @@ -24,6 +24,8 @@ This custom component allows you to integrate Renpho's weight scale data into Ho

![Sensors](docs/images/renpho_google.png)

![Complete View](docs/images/image.png)

## Table of Contents

- [Prerequisites](#prerequisites)
Expand All @@ -35,12 +37,9 @@ This custom component allows you to integrate Renpho's weight scale data into Ho

## Prerequisites

1. You must have a Renpho account. If you don't have one, you can create one [here](https://renpho.com/).
2. You must have a Renpho scale. If you don't have one, you can purchase one [here](https://renpho.com/collections/body-fat-scale).
3. You must have the Renpho app installed on your mobile device. You can download it [here](https://play.google.com/store/apps/details?id=com.renpho.smart&hl=en_US&gl=US) for Android and [here](https://apps.apple.com/us/app/renpho/id1115563582) for iOS.
4. You must have Home Assistant installed and running.
5. You must have the [Home Assistant Community Store (HACS)](https://hacs.xyz/) installed and running.
6. Visual Studio Code is recommended for editing the files.
1. You must have a Renpho scale. If you don't have one, you can purchase one [here](https://renpho.com/collections/body-fat-scale).
2. You must have the Renpho app installed on your mobile device. You can download it [here](https://play.google.com/store/apps/details?id=com.qingniu.renpho&hl=en_US&pli=1) for Android and [here](https://apps.apple.com/ca/app/renpho/id1219889310) for iOS.
4. You must have the [Home Assistant Community Store (HACS)](https://hacs.xyz/) installed and running.

## Installation

Expand Down
86 changes: 56 additions & 30 deletions custom_components/renpho/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,65 +58,91 @@ async def setup_renpho(hass, conf):
user_id = conf.get(CONF_USER_ID, None)
refresh = conf.get(CONF_REFRESH, 600)
renpho = RenphoWeight(CONF_PUBLIC_KEY, email, password, user_id, refresh)

# @callback
# def async_on_start(event):
# hass.async_create_task(async_prepare(hass, renpho, refresh))

# hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, async_on_start)
await renpho.get_info()
hass.data[DOMAIN] = renpho


async def async_prepare(hass, renpho, refresh):
"""Prepare and start polling."""
await renpho.start_polling(refresh)
await renpho.get_info()
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, async_cleanup(renpho))


async def async_cleanup(renpho):
"""Cleanup logic."""
await renpho.stop_polling()

await renpho.close()

# ------------------- Main Method for Testing -------------------

if __name__ == "__main__":

async def main():
import os

from dotenv import load_dotenv

load_dotenv()

email = os.environ.get("EMAIL")
password = os.environ.get("PASSWORD")
user_id = os.environ.get("USER_ID", None)

renpho = RenphoWeight(CONF_PUBLIC_KEY, email, password, user_id)

try:
renpho = RenphoWeight(CONF_PUBLIC_KEY, email, password, user_id)
print("Before polling")
renpho.start_polling(10)
print("After polling")
renpho.get_info_sync()
await renpho.auth()
print("Authentication successful.")

await renpho.get_info()
print("Fetched user info.")

users = await renpho.get_scale_users()
print("Fetched scale users:", users)
get_device_info = await renpho.get_device_info()
print("Fetched device info:", get_device_info)
list_growth_record = await renpho.list_growth_record()
print("Fetched list growth record:", list_growth_record)
list_girth = await renpho.list_girth()
print("Fetched list girth:", list_girth)
list_girth_goal = await renpho.list_girth_goal()
print("Fetched list girth goal:", list_girth_goal)
message_list = await renpho.message_list()
list_growth_record = await renpho.list_growth_record()
print("Fetched list growth record:", list_growth_record)
print("Fetched message list:", message_list)
info = await renpho.get_info()
print("Fetched info:", info)

measurements = await renpho.get_measurements()
print("Fetched measurements:", measurements)

weight = await renpho.get_weight()
print("Fetched weight:", weight[0])

specific_metric = await renpho.get_specific_metric('weight', 'weight')
print(f"Fetched specific metric: {specific_metric}")

# await renpho.start_polling(refresh=1)
# print("Started polling.")

# await renpho.stop_polling()
# print("Stopped polling.")

device_info = await renpho.get_device_info()
print("Fetched device info:", device_info)

latest_model = await renpho.list_latest_model()
print("Fetched latest model:", latest_model)

girth_info = await renpho.list_girth()
print("Fetched girth info:", girth_info)

girth_goal = await renpho.list_girth_goal()
print("Fetched girth goal:", girth_goal)

growth_record = await renpho.list_growth_record()
print("Fetched growth record:", growth_record)

messages = await renpho.message_list()
print("Fetched message list:", messages)

# request_user = await renpho.request_user()
# print("Fetched request user:", request_user)

# reach_goal = await renpho.reach_goal()
# print("Fetched reach_goal:", reach_goal)

except Exception as e:
print(f"An exception occurred: {e}")

input("Press Enter to stop polling")
renpho.stop_polling()
finally:
input("Press Enter to stop polling")
await renpho.close() # This method also stops polling as per your class definition

asyncio.run(main())
Loading

0 comments on commit 3bf2148

Please sign in to comment.