jcgoette / baby_buddy_homeassistant Goto Github PK
View Code? Open in Web Editor NEWThis custom integration provides sensors for Baby Buddy API endpoints.
License: MIT License
This custom integration provides sensors for Baby Buddy API endpoints.
License: MIT License
in constructor, use add_entities(devices, True) instead
if not ssl:
_LOGGER.warning("Use of HTTPS in production environment is highly recommended")
baby_buddy = BabyBuddyData(address, api_key, ssl, sensor_type)
if not baby_buddy.form_address():
return
# TODO: Do not call update() in constructor, use add_entities(devices, True) instead
baby_buddy.entities_update()
sensors = []
for data in baby_buddy.data:
sensors.append(BabyBuddySensor(data, baby_buddy))
add_entities(sensors, False)
# TODO: handle loading of children
def services_children_add(call):
54ad22cce48e8325c55ba8bf649bb9c9b92a46a6
do we need BaseUrlSession?
return address
def session(self):
# TODO: do we need BaseUrlSession?
session = sessions.BaseUrlSession(base_url=self._formed_address)
session.headers = {"Authorization": f"Token {self._api_key}"}
return session
def entities_add(self, endpoint, data):
add = self._session.post(f"{endpoint}/", data=data)
if not add.ok:
_LOGGER.error(
4b2731bc6d1b03eba588f39fb944b2de8808cb8f
Hi,
I have created a herokuapp instance but can't get it to authenticate.
I am putting in https://nameofapp.herokuapp.com/ as the URL
Port: 8000 (does this need to be different?
And putting in my API key
Entity states/attributes in Home Assistant are not updated if entry in Baby Buddy is updated.
For example, if a feed was marked as 45 mL, but then later adjusted to 75 mL, Home Assistant doesn't update existing entity.
Unsure if there is method to update existing Home Assistant entity states/attributes...
Hello,
Thank you for this great integration!
Is it possible to extract the total feeding amount into a sensor directly from the Babybuddy API?
handle unloading of children
add_entities(sensors, True)
# TODO: handle loading of children
def services_children_add(call):
endpoint = ATTR_CHILDREN
data = {
ATTR_FIRST_NAME: call.data.get(ATTR_FIRST_NAME),
ATTR_LAST_NAME: call.data.get(ATTR_LAST_NAME),
ATTR_BIRTH_DATE: call.data.get(ATTR_BIRTH_DATE),
}
baby_buddy_data.entities_add(endpoint, data)
def services_changes_add(call):
endpoint = ATTR_CHANGES
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_TIME: call.data.get(ATTR_TIME),
ATTR_WET: call.data.get(ATTR_WET),
ATTR_SOLID: call.data.get(ATTR_SOLID),
ATTR_COLOR: call.data.get(ATTR_COLOR).lower(),
ATTR_AMOUNT: call.data.get(ATTR_AMOUNT),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
def services_feedings_add(call):
endpoint = ATTR_FEEDINGS
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_START: call.data.get(ATTR_START),
ATTR_END: call.data.get(ATTR_END),
ATTR_TYPE: call.data.get(ATTR_TYPE).lower(),
ATTR_METHOD: call.data.get(ATTR_METHOD).lower(),
ATTR_AMOUNT: call.data.get(ATTR_AMOUNT),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
def services_notes_add(call):
endpoint = ATTR_NOTES
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_NOTE: call.data.get(ATTR_NOTE),
ATTR_TIME: call.data.get(ATTR_TIME),
}
baby_buddy_data.entities_add(endpoint, data)
def services_sleep_add(call):
endpoint = ATTR_SLEEP
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_START: call.data.get(ATTR_START),
ATTR_END: call.data.get(ATTR_END),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
def services_temperature_add(call):
endpoint = ATTR_TEMPERATURE
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_TEMPERATURE: call.data.get(ATTR_TEMPERATURE),
ATTR_TIME: call.data.get(ATTR_TIME),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
"""
def services_timers_add(call):
endpoint = ATTR_TIMERS
data = {}
baby_buddy_data.entities_add(endpoint, data)
"""
def services_tummy_times_add(call):
endpoint = ATTR_TUMMY_TIMES
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_START: call.data.get(ATTR_START),
ATTR_END: call.data.get(ATTR_END),
ATTR_MILESTONE: call.data.get(ATTR_MILESTONE),
}
baby_buddy_data.entities_add(endpoint, data)
def services_weight_add(call):
endpoint = ATTR_WEIGHT
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_WEIGHT: call.data.get(ATTR_WEIGHT),
ATTR_DATE: call.data.get(ATTR_DATE),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
# TODO: handle unloading of children
def services_delete(call):
endpoint = call.data.get(ATTR_ENDPOINT).lower().replace(" ", "-")
data = call.data.get(ATTR_ENTRY)
baby_buddy_data.entities_delete(endpoint, data)
hass.services.register(DOMAIN, "services_children_add", services_children_add)
hass.services.register(DOMAIN, "services_changes_add", services_changes_add)
hass.services.register(DOMAIN, "services_feedings_add", services_feedings_add)
hass.services.register(DOMAIN, "services_notes_add", services_notes_add)
hass.services.register(DOMAIN, "services_sleep_add", services_sleep_add)
hass.services.register(DOMAIN, "services_temperature_add", services_temperature_add)
# TODO: add timers service
"""hass.services.register(DOMAIN, "services_timers_add", services_timers_add)"""
hass.services.register(DOMAIN, "services_tummy_times_add", services_tummy_times_add)
hass.services.register(DOMAIN, "services_weight_add", services_weight_add)
hass.services.register(DOMAIN, "services_delete", services_delete)
class BabyBuddySensor(Entity):
"""Representation of a Baby Buddy Sensor."""
0dc616fa903b06b6b16a8e519092229825b481c4
It would make more sense to see the time from the last feed rather than the amount on the last feeding entity. Now the entity shows the feeding amount. One could make a template sensor, take the last feeding end time attribute and calculate the time from the last feed but via the integration would be easier and cleaner to show in HA.
I'm able to start a timer using the "switch.NAME_last_time" entity but am having issues ending and logging the activity. My test trying to log sleep with the ADD_Sleep service, see below. Since i'm using the "switch.NAME_last_timer" button, it just deletes the previous timer.
- type: button # to start the timer, this works correctly.
tap_action:
action: toggle
entity: switch.NAME_last_timer
- type: button # Looking to stop the previous timer and log sleep.
type_action:
action: call-service
service: add_sleep
entity: switch.NAME_last_timer
timer: true
handle loading of children
add_entities(sensors, True)
# TODO: handle loading of children
def services_children_add(call):
endpoint = ATTR_CHILDREN
data = {
ATTR_FIRST_NAME: call.data.get(ATTR_FIRST_NAME),
ATTR_LAST_NAME: call.data.get(ATTR_LAST_NAME),
ATTR_BIRTH_DATE: call.data.get(ATTR_BIRTH_DATE),
}
baby_buddy_data.entities_add(endpoint, data)
def services_changes_add(call):
endpoint = ATTR_CHANGES
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_TIME: call.data.get(ATTR_TIME),
ATTR_WET: call.data.get(ATTR_WET),
ATTR_SOLID: call.data.get(ATTR_SOLID),
ATTR_COLOR: call.data.get(ATTR_COLOR).lower(),
ATTR_AMOUNT: call.data.get(ATTR_AMOUNT),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
def services_feedings_add(call):
endpoint = ATTR_FEEDINGS
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_START: call.data.get(ATTR_START),
ATTR_END: call.data.get(ATTR_END),
ATTR_TYPE: call.data.get(ATTR_TYPE).lower(),
ATTR_METHOD: call.data.get(ATTR_METHOD).lower(),
ATTR_AMOUNT: call.data.get(ATTR_AMOUNT),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
def services_notes_add(call):
endpoint = ATTR_NOTES
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_NOTE: call.data.get(ATTR_NOTE),
ATTR_TIME: call.data.get(ATTR_TIME),
}
baby_buddy_data.entities_add(endpoint, data)
def services_sleep_add(call):
endpoint = ATTR_SLEEP
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_START: call.data.get(ATTR_START),
ATTR_END: call.data.get(ATTR_END),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
def services_temperature_add(call):
endpoint = ATTR_TEMPERATURE
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_TEMPERATURE: call.data.get(ATTR_TEMPERATURE),
ATTR_TIME: call.data.get(ATTR_TIME),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
"""
def services_timers_add(call):
endpoint = ATTR_TIMERS
data = {}
baby_buddy_data.entities_add(endpoint, data)
"""
def services_tummy_times_add(call):
endpoint = ATTR_TUMMY_TIMES
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_START: call.data.get(ATTR_START),
ATTR_END: call.data.get(ATTR_END),
ATTR_MILESTONE: call.data.get(ATTR_MILESTONE),
}
baby_buddy_data.entities_add(endpoint, data)
def services_weight_add(call):
endpoint = ATTR_WEIGHT
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_WEIGHT: call.data.get(ATTR_WEIGHT),
ATTR_DATE: call.data.get(ATTR_DATE),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
# TODO: handle unloading of children
def services_delete(call):
endpoint = call.data.get(ATTR_ENDPOINT).lower().replace(" ", "-")
data = call.data.get(ATTR_ENTRY)
baby_buddy_data.entities_delete(endpoint, data)
hass.services.register(DOMAIN, "services_children_add", services_children_add)
hass.services.register(DOMAIN, "services_changes_add", services_changes_add)
hass.services.register(DOMAIN, "services_feedings_add", services_feedings_add)
hass.services.register(DOMAIN, "services_notes_add", services_notes_add)
hass.services.register(DOMAIN, "services_sleep_add", services_sleep_add)
hass.services.register(DOMAIN, "services_temperature_add", services_temperature_add)
# TODO: add timers service
"""hass.services.register(DOMAIN, "services_timers_add", services_timers_add)"""
hass.services.register(DOMAIN, "services_tummy_times_add", services_tummy_times_add)
hass.services.register(DOMAIN, "services_weight_add", services_weight_add)
hass.services.register(DOMAIN, "services_delete", services_delete)
class BabyBuddySensor(Entity):
"""Representation of a Baby Buddy Sensor."""
a34cc2b3f9b8c8807ff3b5b5153da2d3530a1761
I'm integrating a kitchen scale to record food measurements, so I'd like to add decimal point options to the feeding switch.
I've done this on my local version by changing line 91 in switch.py to
vol.Optional(ATTR_AMOUNT): cv.positive_float,
Just sharing in case you want to integrate it.
Providing a string for its state, while the device class is 'timestamp', this is not valid and will be unsupported from Home Assistant 2022.2.
DRY
sensor = [sensors for sensors in self.entities_get() if sensors[0] == sensor]
return sensor
def entities_delete(self, endpoint, data):
# TODO: DRY
session = sessions.BaseUrlSession(base_url=self.form_address())
session.headers = {"Authorization": f"Token {self._api_key}"}
delete = session.delete(f"{endpoint}/{data}/")
if not delete.ok:
_LOGGER.error(
"Cannot delete %s, check service fields",
endpoint,
)
a8ceb7e9d2877f724c228a39175fac246975ba3c
refactor entity creation
sensors = []
# TODO: refactor entity creation
for entity in baby_buddy_data.entities_get():
entity_list = [baby_buddy_data]
for part in entity:
f1e6a2bffb70e7f171015311967f381bea9343be
Logger: homeassistant.components.sensor
Source: components/sensor/init.py:151
Integration: Sensor (documentation, issues)
custom_components.babybuddy.const is setting 'unit_of_measurement' on an instance of SensorEntityDescription, this is not valid and will be unsupported from Home Assistant 2021.11. Please report it to the custom component author.
handle unloading of children
add_entities(sensors, True)
# TODO: handle loading of children
def services_children_add(call):
endpoint = ATTR_CHILDREN
data = {
ATTR_FIRST_NAME: call.data.get(ATTR_FIRST_NAME),
ATTR_LAST_NAME: call.data.get(ATTR_LAST_NAME),
ATTR_BIRTH_DATE: call.data.get(ATTR_BIRTH_DATE),
}
baby_buddy_data.entities_add(endpoint, data)
def services_changes_add(call):
endpoint = ATTR_CHANGES
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_TIME: call.data.get(ATTR_TIME),
ATTR_WET: call.data.get(ATTR_WET),
ATTR_SOLID: call.data.get(ATTR_SOLID),
ATTR_COLOR: call.data.get(ATTR_COLOR).lower(),
ATTR_AMOUNT: call.data.get(ATTR_AMOUNT),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
def services_feedings_add(call):
endpoint = ATTR_FEEDINGS
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_START: call.data.get(ATTR_START),
ATTR_END: call.data.get(ATTR_END),
ATTR_TYPE: call.data.get(ATTR_TYPE).lower(),
ATTR_METHOD: call.data.get(ATTR_METHOD).lower(),
ATTR_AMOUNT: call.data.get(ATTR_AMOUNT),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
def services_notes_add(call):
endpoint = ATTR_NOTES
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_NOTE: call.data.get(ATTR_NOTE),
ATTR_TIME: call.data.get(ATTR_TIME),
}
baby_buddy_data.entities_add(endpoint, data)
def services_sleep_add(call):
endpoint = ATTR_SLEEP
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_START: call.data.get(ATTR_START),
ATTR_END: call.data.get(ATTR_END),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
def services_temperature_add(call):
endpoint = ATTR_TEMPERATURE
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_TEMPERATURE: call.data.get(ATTR_TEMPERATURE),
ATTR_TIME: call.data.get(ATTR_TIME),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
"""
def services_timers_add(call):
endpoint = ATTR_TIMERS
data = {}
baby_buddy_data.entities_add(endpoint, data)
"""
def services_tummy_times_add(call):
endpoint = ATTR_TUMMY_TIMES
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_START: call.data.get(ATTR_START),
ATTR_END: call.data.get(ATTR_END),
ATTR_MILESTONE: call.data.get(ATTR_MILESTONE),
}
baby_buddy_data.entities_add(endpoint, data)
def services_weight_add(call):
endpoint = ATTR_WEIGHT
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_WEIGHT: call.data.get(ATTR_WEIGHT),
ATTR_DATE: call.data.get(ATTR_DATE),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
# TODO: handle unloading of children
def services_delete(call):
endpoint = call.data.get(ATTR_ENDPOINT).lower().replace(" ", "-")
data = call.data.get(ATTR_ENTRY)
baby_buddy_data.entities_delete(endpoint, data)
hass.services.register(DOMAIN, "services_children_add", services_children_add)
hass.services.register(DOMAIN, "services_changes_add", services_changes_add)
hass.services.register(DOMAIN, "services_feedings_add", services_feedings_add)
hass.services.register(DOMAIN, "services_notes_add", services_notes_add)
hass.services.register(DOMAIN, "services_sleep_add", services_sleep_add)
hass.services.register(DOMAIN, "services_temperature_add", services_temperature_add)
# TODO: add timers service
"""hass.services.register(DOMAIN, "services_timers_add", services_timers_add)"""
hass.services.register(DOMAIN, "services_tummy_times_add", services_tummy_times_add)
hass.services.register(DOMAIN, "services_weight_add", services_weight_add)
hass.services.register(DOMAIN, "services_delete", services_delete)
class BabyBuddySensor(Entity):
"""Representation of a Baby Buddy Sensor."""
9d7d37b48c73a4fc1ecf5260652a3c30e45b057f
Interesting issue when working on #46. Occurs when duration of tummy time (and presumably other duration field endpoints) == 24 hours (the BB maximum value).
2021-11-07 18:03:30 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/home/jcgoette/core/homeassistant/helpers/config_validation.py", line 400, in time_period_str
hour = int(parsed[0])
ValueError: invalid literal for int() with base 10: '1 00'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/jcgoette/core/homeassistant/helpers/update_coordinator.py", line 134, in _handle_refresh_interval
await self._async_refresh(log_failures=True, scheduled=True)
File "/home/jcgoette/core/homeassistant/helpers/update_coordinator.py", line 265, in _async_refresh
update_callback()
File "/home/jcgoette/core/homeassistant/helpers/update_coordinator.py", line 325, in _handle_coordinator_update
self.async_write_ha_state()
File "/home/jcgoette/core/homeassistant/helpers/entity.py", line 480, in async_write_ha_state
self._async_write_ha_state()
File "/home/jcgoette/core/homeassistant/helpers/entity.py", line 513, in _async_write_ha_state
state = self._stringify_state()
File "/home/jcgoette/core/homeassistant/helpers/entity.py", line 486, in _stringify_state
if (state := self.state) is None:
File "/home/jcgoette/core/homeassistant/components/sensor/__init__.py", line 273, in state
value = self.native_value
File "/home/jcgoette/core/config/custom_components/babybuddy/sensor.py", line 340, in native_value
return self.entity_description.state_key(data)
File "/home/jcgoette/core/config/custom_components/babybuddy/const.py", line 122, in <lambda>
time_period_str(value[ATTR_DURATION]).total_seconds() / 60
File "/home/jcgoette/core/homeassistant/helpers/config_validation.py", line 407, in time_period_str
raise vol.Invalid(TIME_PERIOD_ERROR.format(value)) from err
voluptuous.error.Invalid: offset 1 00:00:00 should be format 'HH:MM', 'HH:MM:SS' or 'HH:MM:SS.F'
Not sure yet if should work on homeassistant/helpers/config_validation.py
, account for in BB, or account for in baby_buddy_homeassistant.
The last tummy time entity does not have a unit. Now only the number is displayed in HA.
Hey @jcoette, I have a small problem. The 's' is stripped from the last name in the interface of HA. I guess it's because of this line. Is this needed?
I updated baby buddy and home assistant at the same time so I'm not sure which one is the culprit, but services stopped working as of the 1 April home assistant update.
Happen to anyone else? Any ideas what it could be?
Please help me out.
I've deployed the Baby Buddy on Heroku, but when I try to integrate it in Home Assistant it asks for a host and API.
What do I enter as the host?
It keeps saying that it can't connect when I enter the URL.
Thanks in advance!
Feature Request for allowing http connections to baby buddy using non-standard ports.
Attempting to run a script through home assistant to log a diaper change with the press of a button. This has worked well up until now, for some reason it is no longer working. Home assistant gives the following log error
Could not create changes. error: {'time': ['Date/time can not be in the future.']}
When calling the diaper change service manually the same error appears.
Logging normally through the web page works fine.
add timers service
add_entities(sensors, True)
# TODO: handle loading of children
def services_children_add(call):
endpoint = ATTR_CHILDREN
data = {
ATTR_FIRST_NAME: call.data.get(ATTR_FIRST_NAME),
ATTR_LAST_NAME: call.data.get(ATTR_LAST_NAME),
ATTR_BIRTH_DATE: call.data.get(ATTR_BIRTH_DATE),
}
baby_buddy_data.entities_add(endpoint, data)
def services_changes_add(call):
endpoint = ATTR_CHANGES
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_TIME: call.data.get(ATTR_TIME),
ATTR_WET: call.data.get(ATTR_WET),
ATTR_SOLID: call.data.get(ATTR_SOLID),
ATTR_COLOR: call.data.get(ATTR_COLOR).lower(),
ATTR_AMOUNT: call.data.get(ATTR_AMOUNT),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
def services_feedings_add(call):
endpoint = ATTR_FEEDINGS
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_START: call.data.get(ATTR_START),
ATTR_END: call.data.get(ATTR_END),
ATTR_TYPE: call.data.get(ATTR_TYPE).lower(),
ATTR_METHOD: call.data.get(ATTR_METHOD).lower(),
ATTR_AMOUNT: call.data.get(ATTR_AMOUNT),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
def services_notes_add(call):
endpoint = ATTR_NOTES
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_NOTE: call.data.get(ATTR_NOTE),
ATTR_TIME: call.data.get(ATTR_TIME),
}
baby_buddy_data.entities_add(endpoint, data)
def services_sleep_add(call):
endpoint = ATTR_SLEEP
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_START: call.data.get(ATTR_START),
ATTR_END: call.data.get(ATTR_END),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
def services_temperature_add(call):
endpoint = ATTR_TEMPERATURE
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_TEMPERATURE: call.data.get(ATTR_TEMPERATURE),
ATTR_TIME: call.data.get(ATTR_TIME),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
"""
def services_timers_add(call):
endpoint = ATTR_TIMERS
data = {}
baby_buddy_data.entities_add(endpoint, data)
"""
def services_tummy_times_add(call):
endpoint = ATTR_TUMMY_TIMES
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_START: call.data.get(ATTR_START),
ATTR_END: call.data.get(ATTR_END),
ATTR_MILESTONE: call.data.get(ATTR_MILESTONE),
}
baby_buddy_data.entities_add(endpoint, data)
def services_weight_add(call):
endpoint = ATTR_WEIGHT
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_WEIGHT: call.data.get(ATTR_WEIGHT),
ATTR_DATE: call.data.get(ATTR_DATE),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
# TODO: handle unloading of children
def services_delete(call):
endpoint = call.data.get(ATTR_ENDPOINT).lower().replace(" ", "-")
data = call.data.get(ATTR_ENTRY)
baby_buddy_data.entities_delete(endpoint, data)
hass.services.register(DOMAIN, "services_children_add", services_children_add)
hass.services.register(DOMAIN, "services_changes_add", services_changes_add)
hass.services.register(DOMAIN, "services_feedings_add", services_feedings_add)
hass.services.register(DOMAIN, "services_notes_add", services_notes_add)
hass.services.register(DOMAIN, "services_sleep_add", services_sleep_add)
hass.services.register(DOMAIN, "services_temperature_add", services_temperature_add)
# TODO: add timers service
"""hass.services.register(DOMAIN, "services_timers_add", services_timers_add)"""
hass.services.register(DOMAIN, "services_tummy_times_add", services_tummy_times_add)
hass.services.register(DOMAIN, "services_weight_add", services_weight_add)
hass.services.register(DOMAIN, "services_delete", services_delete)
class BabyBuddySensor(Entity):
"""Representation of a Baby Buddy Sensor."""
0d64a427c0a5c5d9e5fe3009e9dcc94ac6cbe2af
refactor entity creation
sensors = []
# TODO: refactor entity creation
for entity in baby_buddy_data.entities_get():
entity_list = [baby_buddy_data]
for part in entity:
e434c44564be1372efb071562b8dceaa8df8d192
When calling any of the services to add records to Baby Buddy via Home Assistant, I'm getting the following error
2022-01-03 08:19:56 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Unexpected error for call_service at pos 1: 0, message='Attempt to decode JSON with unexpected mimetype: text/html', url=URL('http://192.168.1.70:10405/api/changes/') Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 381, in _async_step await getattr(self, handler)() File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 584, in _async_call_service_step await service_task File "/usr/src/homeassistant/homeassistant/core.py", line 1495, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1530, in _execute_service await handler.job.target(service_call) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 691, in handle_service await service.entity_service_call( File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 663, in entity_service_call future.result() # pop exception if have File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 896, in async_request_call await coro File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 700, in _handle_entity_call await result File "/config/custom_components/babybuddy/sensor.py", line 199, in async_add_diaper_change await self.coordinator.client.async_post(ATTR_CHANGES, data) File "/config/custom_components/babybuddy/client.py", line 64, in async_post error = await resp.json() File "/usr/local/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 1103, in json raise ContentTypeError( aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/html', url=URL('http://192.168.1.70:10405/api/changes/')
2022-01-03 08:19:56 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [2924599784] Error handling message: Unknown error Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response await func(hass, connection, msg) File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 527, in handle_execute_script await script_obj.async_run(msg.get("variables"), context=context) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1260, in async_run await asyncio.shield(run.async_run()) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 363, in async_run await self._async_step(log_exceptions=False) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 381, in _async_step await getattr(self, handler)() File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 584, in _async_call_service_step await service_task File "/usr/src/homeassistant/homeassistant/core.py", line 1495, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1530, in _execute_service await handler.job.target(service_call) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 691, in handle_service await service.entity_service_call( File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 663, in entity_service_call future.result() # pop exception if have File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 896, in async_request_call await coro File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 700, in _handle_entity_call await result File "/config/custom_components/babybuddy/sensor.py", line 199, in async_add_diaper_change await self.coordinator.client.async_post(ATTR_CHANGES, data) File "/config/custom_components/babybuddy/client.py", line 64, in async_post error = await resp.json() File "/usr/local/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 1103, in json raise ContentTypeError( aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/html', url=URL('http://192.168.1.70:10405/api/changes/')
This is running version 2021.12.7
of Home assistant & version V2.3.0
of BabyBuddy - Downgrading baby buddy did not change the issue
My son has now been born and we've started using the integration. I had previously set up a series of buttons in HA that logged feeds and changes to BB without any issue. This is an example of the script called by a button press:
service: babybuddy.services_feedings_add data: child: sensor.baby_grabowski type: Breast milk method: Left breast amount: '1' start: '{{ now() }}' end: '{{ now() }}'
For changes I used:
service: babybuddy.services_changes_add data: child: sensor.baby_grabowski time: '{{ now() }}' wet: false solid: true color: Black
With the recent updates to the integration, this no longer works as I believe it is looking for a timer. I can't figure out what to do (especially with the sleep deprivation!). Can someone suggest how to edit the above script to be able to quickly log a feed with the required attributes. I'm not bothered about how much or how long (for now) as I simply wanted the feed to be logged. As I said, this worked fine before the recent updates, but the readme isn't detailed enough for me to figure out integrating timers etc.
Any help is MUCH appreciated (especially for the very tired WAP factor!!)
less expensive connection test
self._sensor_type = sensor_type
self._formed_address = self.form_address()
self._session = self.session()
self.data = self.entities_get()
# TODO: less expensive connection test
def form_address(self):
if self._ssl:
address = f"https://{self._address}/api/"
c1ee2d1c52fffc2aebca69a3fab435cc434ee479
Would be nice to have attribute for Last diaper change entity to show wet/solid/wet and solid rather than having two attributes showing true/false. This way would be easier to show the state in HA.
DRY
sensor = [sensors for sensors in self.entities_get() if sensors[0] == sensor]
return sensor
def entities_delete(self, endpoint, data):
# TODO: DRY
session = sessions.BaseUrlSession(base_url=self.form_address())
session.headers = {"Authorization": f"Token {self._api_key}"}
delete = session.delete(f"{endpoint}/{data}/")
if not delete.ok:
_LOGGER.error(
"Cannot delete %s, check service fields",
endpoint,
)
152e51d6b1ddcd16f1319632da0410c8de9ff553
Adding tummy / sleep time always fails but i'm not sure why.
Here is my service data:
service: babybuddy.services_tummy_times_add
data:
child: sensor.baby_nandhra_pezone
start: 2021-07-13 09:15
end: 2021-07-13 09:20
Here is what the logs say
Cannot create tummy-times, check service fields
Here is the baby sensor details as seen in HA.
id: 1
first_name: Baby
last_name: Nandhra-Pezone
birth_date: 2021-08-09
slug: baby-nandhra-pezone
picture: null
child_name: Baby_Nandhra-Pezone
endpoint: children
friendly_name: Baby Nandhra-Pezone
icon: mdi:baby-face-outline
From what i can see the service fields are right so I think something else might be going on here. Oddly though it did work the once but not since. The only thing i've changed since at all is the start and end times.
Recently this integration stopped working for me, I suspect after a Baby Buddy update in the 1.10 range.
In the Home Assistant logs I see this frequently:
2022-04-21 14:56:10 ERROR (MainThread) [custom_components.babybuddy] Error fetching babybuddy data: Cannot connect to host babybuddy:80 ssl:default [Connect call failed ('172.20.0.8', 80)]
That's really weird because I configured HACS Baby Buddy to use port 8000, which should be the default. I don't understand where port 80 comes from.
Note that Baby Buddy and Home Assistant both run as Docker containers, hostnames babybuddy
and homeassistant
.
Hi there. Firstly, thank you for creating this integration. I'm about 3 weeks away from my first child being born and would like to be able to incorporate some kind of logging system into HA so that my partner and I can keep track of what has/hasn't happened with the baby,
I am totally green when it comes to a lot of this stuff so have been fumbling my way through setting up a working Home Assistant setup that i'm currently happy with but have been really struggling to get Baby Buddy up and running. I first tried installing it using Docker Compose on a Raspberry Pi 3B, which I have some other containers running on without issue. But I couldn't for the life of me figure out Baby Buddy. The database seem to generate well enough but i can't connect to the app via the local IP address.
After several hours reading over the various threads on the repo, and feeling very in over my head, i thought i'd give it a shot setting it up via the Heroku method. why not? I wasn't holding out much hope but i registered an account and hit the "Deploy to Heroku" button on the Baby Buddy repo and lo and behold, it installed and worked without a hitch. I now have an external URL hosted on Heroku that I can access a Baby Buddy instance. hooray!
However, this victory was quickly quashed as I now can't seem to connect it to HA via that URL. Seemed like it should be easy, no? I installed your component and setup my config like so:
sensor:
- platform: babybuddy
address: http://*****.herokuapp.com/
api_key: **************
ssl: false
Rebooted HA and crossed my fingers - but no cigar. No senors populated into HA after a reboot. I even tried creating a few sleep and tummy time events in Baby Buddy as I thought that perhaps it wouldn't create sensors if the logs were empty, but still nada.
I'm really not sure what I'm doing wrong. Any advice or troubleshooting tips you might have would be super appreciated.
This add-on is great for the use case of seeing the last time baby was fed, changed, etc. However, I'm having trouble using it to view historical data and trends because the sensors don't represent true time series.
For comparison, look at how most sensors are plotted in the history tab of HA:
Imagine if one of those sensors was "sleeping", so you could see a state timeline of when your baby slept. That's what I want.
(Edited to make the desired output clearer and remove references to other programs)
Any ideas why my home assistant integration isn't connecting well with my babybuddy install? My babybuddy install was pulled via docker-compose yesterday (April 14th). Here are the stats of my HA install:
Home Assistant Version
Installation Version: core-2021.4.4
Installation Type: Home Assistant OS
HA configuration.yaml
sensor:
- platform: babybuddy
address: baby-dev.*********
api_key: !secret babybuddy_api_key
sensor_type:
- sleep
HA Log Output
Logger: homeassistant.components.sensor
Source: custom_components/babybuddy/sensor.py:173
Integration: Sensor (documentation, issues)
First occurred: 11:17:39 AM (1 occurrences)
Last logged: 11:17:39 AM`
`Error while setting up babybuddy platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 205, in _async_setup_platform
await asyncio.shield(task)
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/babybuddy/sensor.py", line 56, in setup_platform
for entity in baby_buddy_data.entities_get():
File "/config/custom_components/babybuddy/sensor.py", line 173, in entities_get
children = session.get("children/").json()
File "/usr/local/lib/python3.8/site-packages/requests/models.py", line 900, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/local/lib/python3.8/site-packages/simplejson/__init__.py", line 525, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python3.8/site-packages/simplejson/decoder.py", line 370, in decode
obj, end = self.raw_decode(s)
File "/usr/local/lib/python3.8/site-packages/simplejson/decoder.py", line 400, in raw_decode
return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Right after installation of babybuddy and the sensor via hacs, this error showed up. Perhaps it has something to do with the new installation of babybuddy and an empty database after installation.
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 199, in _async_setup_platform
await asyncio.shield(task)
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/babybuddy/sensor.py", line 42, in setup_platform
for entity in baby_buddy_data.entities_get():
File "/config/custom_components/babybuddy/sensor.py", line 132, in entities_get
children = session.get("children/").json()
File "/usr/local/lib/python3.8/site-packages/requests/models.py", line 900, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/local/lib/python3.8/site-packages/simplejson/__init__.py", line 525, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python3.8/site-packages/simplejson/decoder.py", line 370, in decode
obj, end = self.raw_decode(s)
File "/usr/local/lib/python3.8/site-packages/simplejson/decoder.py", line 400, in raw_decode
return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
handle loading of children
add_entities(sensors, True)
# TODO: handle loading of children
def services_children_add(call):
endpoint = ATTR_CHILDREN
data = {
ATTR_FIRST_NAME: call.data.get(ATTR_FIRST_NAME),
ATTR_LAST_NAME: call.data.get(ATTR_LAST_NAME),
ATTR_BIRTH_DATE: call.data.get(ATTR_BIRTH_DATE),
}
baby_buddy_data.entities_add(endpoint, data)
def services_changes_add(call):
endpoint = ATTR_CHANGES
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_TIME: call.data.get(ATTR_TIME),
ATTR_WET: call.data.get(ATTR_WET),
ATTR_SOLID: call.data.get(ATTR_SOLID),
ATTR_COLOR: call.data.get(ATTR_COLOR).lower(),
ATTR_AMOUNT: call.data.get(ATTR_AMOUNT),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
def services_feedings_add(call):
endpoint = ATTR_FEEDINGS
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_START: call.data.get(ATTR_START),
ATTR_END: call.data.get(ATTR_END),
ATTR_TYPE: call.data.get(ATTR_TYPE).lower(),
ATTR_METHOD: call.data.get(ATTR_METHOD).lower(),
ATTR_AMOUNT: call.data.get(ATTR_AMOUNT),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
def services_notes_add(call):
endpoint = ATTR_NOTES
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_NOTE: call.data.get(ATTR_NOTE),
ATTR_TIME: call.data.get(ATTR_TIME),
}
baby_buddy_data.entities_add(endpoint, data)
def services_sleep_add(call):
endpoint = ATTR_SLEEP
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_START: call.data.get(ATTR_START),
ATTR_END: call.data.get(ATTR_END),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
def services_temperature_add(call):
endpoint = ATTR_TEMPERATURE
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_TEMPERATURE: call.data.get(ATTR_TEMPERATURE),
ATTR_TIME: call.data.get(ATTR_TIME),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
"""
def services_timers_add(call):
endpoint = ATTR_TIMERS
data = {}
baby_buddy_data.entities_add(endpoint, data)
"""
def services_tummy_times_add(call):
endpoint = ATTR_TUMMY_TIMES
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_START: call.data.get(ATTR_START),
ATTR_END: call.data.get(ATTR_END),
ATTR_MILESTONE: call.data.get(ATTR_MILESTONE),
}
baby_buddy_data.entities_add(endpoint, data)
def services_weight_add(call):
endpoint = ATTR_WEIGHT
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_WEIGHT: call.data.get(ATTR_WEIGHT),
ATTR_DATE: call.data.get(ATTR_DATE),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
# TODO: handle unloading of children
def services_delete(call):
endpoint = call.data.get(ATTR_ENDPOINT).lower().replace(" ", "-")
data = call.data.get(ATTR_ENTRY)
baby_buddy_data.entities_delete(endpoint, data)
hass.services.register(DOMAIN, "services_children_add", services_children_add)
hass.services.register(DOMAIN, "services_changes_add", services_changes_add)
hass.services.register(DOMAIN, "services_feedings_add", services_feedings_add)
hass.services.register(DOMAIN, "services_notes_add", services_notes_add)
hass.services.register(DOMAIN, "services_sleep_add", services_sleep_add)
hass.services.register(DOMAIN, "services_temperature_add", services_temperature_add)
# TODO: add timers service
"""hass.services.register(DOMAIN, "services_timers_add", services_timers_add)"""
hass.services.register(DOMAIN, "services_tummy_times_add", services_tummy_times_add)
hass.services.register(DOMAIN, "services_weight_add", services_weight_add)
hass.services.register(DOMAIN, "services_delete", services_delete)
class BabyBuddySensor(Entity):
"""Representation of a Baby Buddy Sensor."""
96cd835f2a74669490781eea9d42d89e921a5fd2
can reduce api outbound data transfer further by only querying necessary endpoints
@property
def icon(self):
"""Return the icon to use in Baby Buddy frontend."""
if self._data.get(ATTR_ENDPOINT) == ATTR_CHANGES:
return "mdi:paper-roll-outline"
elif self._data.get(ATTR_ENDPOINT) == ATTR_FEEDINGS:
return "mdi:baby-bottle-outline"
elif self._data.get(ATTR_ENDPOINT) == ATTR_NOTES:
return "mdi:note-multiple-outline"
elif self._data.get(ATTR_ENDPOINT) == ATTR_SLEEP:
return "mdi:sleep"
elif self._data.get(ATTR_ENDPOINT) == ATTR_TEMPERATURE:
return "mdi:thermometer"
elif self._data.get(ATTR_ENDPOINT) == ATTR_TIMERS:
return "mdi:timer-sand"
elif self._data.get(ATTR_ENDPOINT) == ATTR_TUMMY_TIMES:
return "mdi:baby"
elif self._data.get(ATTR_ENDPOINT) == ATTR_WEIGHT:
return "mdi:scale-bathroom"
return "mdi:baby-face-outline"
# TODO: can reduce api outbound data transfer further by only querying necessary endpoints
def update(self):
"""Update data from Baby Buddy for the sensor."""
if not self._baby_buddy.form_address():
return
try:
self._baby_buddy.entities_update()
self._data = [
data
for data in self._baby_buddy.data
if data.get(ATTR_ENDPOINT) == self._data.get(ATTR_ENDPOINT)
and data.get(ATTR_CHILD_NAME) == self._data.get(ATTR_CHILD_NAME)
][0]
except IndexError:
_LOGGER.error(
"Baby Buddy database entry %s has been removed since last Home Assistant start",
647aa7b3f9f75e6fe7b0fa294461f863f6acda77
add timers service
add_entities(sensors, True)
# TODO: handle loading of children
def services_children_add(call):
endpoint = ATTR_CHILDREN
data = {
ATTR_FIRST_NAME: call.data.get(ATTR_FIRST_NAME),
ATTR_LAST_NAME: call.data.get(ATTR_LAST_NAME),
ATTR_BIRTH_DATE: call.data.get(ATTR_BIRTH_DATE),
}
baby_buddy_data.entities_add(endpoint, data)
def services_changes_add(call):
endpoint = ATTR_CHANGES
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_TIME: call.data.get(ATTR_TIME),
ATTR_WET: call.data.get(ATTR_WET),
ATTR_SOLID: call.data.get(ATTR_SOLID),
ATTR_COLOR: call.data.get(ATTR_COLOR).lower(),
ATTR_AMOUNT: call.data.get(ATTR_AMOUNT),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
def services_feedings_add(call):
endpoint = ATTR_FEEDINGS
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_START: call.data.get(ATTR_START),
ATTR_END: call.data.get(ATTR_END),
ATTR_TYPE: call.data.get(ATTR_TYPE).lower(),
ATTR_METHOD: call.data.get(ATTR_METHOD).lower(),
ATTR_AMOUNT: call.data.get(ATTR_AMOUNT),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
def services_notes_add(call):
endpoint = ATTR_NOTES
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_NOTE: call.data.get(ATTR_NOTE),
ATTR_TIME: call.data.get(ATTR_TIME),
}
baby_buddy_data.entities_add(endpoint, data)
def services_sleep_add(call):
endpoint = ATTR_SLEEP
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_START: call.data.get(ATTR_START),
ATTR_END: call.data.get(ATTR_END),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
def services_temperature_add(call):
endpoint = ATTR_TEMPERATURE
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_TEMPERATURE: call.data.get(ATTR_TEMPERATURE),
ATTR_TIME: call.data.get(ATTR_TIME),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
"""
def services_timers_add(call):
endpoint = ATTR_TIMERS
data = {}
baby_buddy_data.entities_add(endpoint, data)
"""
def services_tummy_times_add(call):
endpoint = ATTR_TUMMY_TIMES
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_START: call.data.get(ATTR_START),
ATTR_END: call.data.get(ATTR_END),
ATTR_MILESTONE: call.data.get(ATTR_MILESTONE),
}
baby_buddy_data.entities_add(endpoint, data)
def services_weight_add(call):
endpoint = ATTR_WEIGHT
data = {
ATTR_CHILD: hass.states.get(call.data.get(ATTR_CHILD)).attributes.get("id"),
ATTR_WEIGHT: call.data.get(ATTR_WEIGHT),
ATTR_DATE: call.data.get(ATTR_DATE),
ATTR_NOTES: call.data.get(ATTR_NOTES),
}
baby_buddy_data.entities_add(endpoint, data)
# TODO: handle unloading of children
def services_delete(call):
endpoint = call.data.get(ATTR_ENDPOINT).lower().replace(" ", "-")
data = call.data.get(ATTR_ENTRY)
baby_buddy_data.entities_delete(endpoint, data)
hass.services.register(DOMAIN, "services_children_add", services_children_add)
hass.services.register(DOMAIN, "services_changes_add", services_changes_add)
hass.services.register(DOMAIN, "services_feedings_add", services_feedings_add)
hass.services.register(DOMAIN, "services_notes_add", services_notes_add)
hass.services.register(DOMAIN, "services_sleep_add", services_sleep_add)
hass.services.register(DOMAIN, "services_temperature_add", services_temperature_add)
# TODO: add timers service
"""hass.services.register(DOMAIN, "services_timers_add", services_timers_add)"""
hass.services.register(DOMAIN, "services_tummy_times_add", services_tummy_times_add)
hass.services.register(DOMAIN, "services_weight_add", services_weight_add)
hass.services.register(DOMAIN, "services_delete", services_delete)
class BabyBuddySensor(Entity):
"""Representation of a Baby Buddy Sensor."""
8085efbc3cdc7253ecd11b800f8e1488703a5cb8
Hello,
Since the last (big) update, I added the integration from UI successfully, but I only have 4 select entities and this error:
2021-09-05 12:47:51 ERROR (MainThread) [custom_components.babybuddy] Authentication failed while fetching babybuddy data: 403, message='Forbidden', url=URL('https://mybabybuddy/api/children/')
On babybuddy :
Forbidden: /api/children/
I tried to reset my api key multiple times but same issue :(
From babybuddy/babybuddy#219, it looks like possibly creating way more request sessions than necessary d/t this code:
baby_buddy_homeassistant/custom_components/babybuddy/sensor.py
Lines 317 to 321 in b4d6932
I'm building a Lovelace UI for BabyBuddy, and would like to be able to display the elapsed duration of a running timer, eg to be able to quickly tell how long a nap or feeding has been going on from within HA.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.