Skip to content

Commit

Permalink
v2024.5.0 First public version
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroenterheerdt committed May 22, 2024
1 parent e1e3b35 commit 712a902
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 49 deletions.
28 changes: 21 additions & 7 deletions custom_components/grill_buddy/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
PROBE_SOURCE_TYPE_VALUE = "source_type_value"
PROBE_TARGET_TEMPERATURE = "probe_target_temperature"


# Defaults
PROBE_UPPER_BOUND_DEFAULT = None
PROBE_LOWER_BOUND_DEFAULT = None
Expand All @@ -63,18 +62,33 @@
AT_TARGET_TEMPERATURE = "at_target_temperature"
BELOW_TARGET_TEMPERATURE = "below_target_temperature"
ABOVE_TARGET_TEMPERATURE = "above_target_temperature"
WITHIN_BOUNDS = "within_bounds"
OUTSIDE_BOUNDS = "outside_bounds"
BELOW_LOWER_BOUND = "below_lower_bound"
ABOVE_LOWER_BOUND = "above_lower_bound"
ABOVE_UPPER_BOUND = "above_upper_bound"
BELOW_UPPER_BOUND = "below_upper_bound"
WITHIN_BOUNDS = "within_range"
OUTSIDE_BOUNDS = "outside_range"
BELOW_LOWER_BOUND = "below_lower_threshold"
ABOVE_LOWER_BOUND = "above_lower_threshold"
ABOVE_UPPER_BOUND = "above_upper_threshold"
BELOW_UPPER_BOUND = "below_upper_threshold"
GOAL_NOT_REACHED = "goal_not_reached"
GOAL_REACHED = "goal_reached"

# State update settings
STATE_UPDATE_SETTINGS = "stateupdatesettings"
STATE_UPDATE_SETTING_ID = "stateupdatesetting_id"
STATE_UPDATE_SETTING_NAME = "stateupdatesetting_name"

# Sensor attributes
SENSOR_ATTR_ID = "ID"
SENSOR_ATTR_SOURCE = "Source"
SENSOR_ATTR_PRESET = "Preset"
SENSOR_ATTR_TARGET_TEMPERATURE = "Target temperature"
SENSOR_ATTR_STATUS = "Status"
SENSOR_ATTR_GOAL_SPECIFIC_STATUS = "Goal specific status"
SENSOR_ATTR_STATE_UPDATE_SETTING = "Goal"
SENSOR_ATTR_UPPER_BOUND = "Upper threshold"
SENSOR_ATTR_LOWER_BOUND = "Lower threshold"
SENSOR_ATTR_SOURCE_TYPE = "Get target temperature from"
SENSOR_ATTR_TIME_TO_TARGET = "Time to target (s)"

# Conversion factors
K_TO_C_FACTOR = 273.15 # K-factor = C, C+factor=K

Expand Down
18 changes: 9 additions & 9 deletions custom_components/grill_buddy/frontend/dist/grill-buddy.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"name": "Name",
"source": "Source",
"preset": "Preset",
"state_update_setting": "Update state when",
"upper_bound": "Upper bound",
"lower_bound": "Lower bound",
"state_update_setting": "Goal",
"upper_bound": "Upper threshold",
"lower_bound": "Lower threshold",
"sourcetype": "Get target temperature from",
"sourcetypes": {
"preset": "Preset",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"name": "Naam",
"source": "Bron",
"preset": "Instelling",
"state_update_setting": "Pas status aan als",
"state_update_setting": "Doel",
"upper_bound": "Minimum",
"lower_bound": "Maximum",
"sourcetype": "Stel doeltemperatuur in met",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/grill_buddy/frontend/src/grill-buddy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class GrillBuddyPanel extends LitElement {
this.hass.language,
)}
<a
href="https://community.home-assistant.io/t/smart-irrigation-save-water-by-precisely-watering-your-lawn-garden"
href="https://community.home-assistant.io/t/grill-buddy-your-grilling-companion"
>${localize(
"panels.help.cards.how-to-get-help.community-forum",
this.hass.language,
Expand Down
61 changes: 37 additions & 24 deletions custom_components/grill_buddy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
BELOW_UPPER_BOUND,
COORDINATOR,
DOMAIN,
GOAL_NOT_REACHED,
GOAL_REACHED,
MANUFACTURER,
NAME,
OUTSIDE_BOUNDS,
Expand All @@ -46,6 +48,16 @@
PROBE_TEMPERATURE,
PROBE_UPPER_BOUND,
PROBES,
SENSOR_ATTR_ID,
SENSOR_ATTR_SOURCE,
SENSOR_ATTR_STATE_UPDATE_SETTING,
SENSOR_ATTR_LOWER_BOUND,
SENSOR_ATTR_TIME_TO_TARGET,
SENSOR_ATTR_TARGET_TEMPERATURE,
SENSOR_ATTR_GOAL_SPECIFIC_STATUS,
SENSOR_ATTR_PRESET,
SENSOR_ATTR_STATUS,
SENSOR_ATTR_UPPER_BOUND,
SENSOR_ICON,
STATE_UPDATE_SETTING_ID,
STATE_UPDATE_SETTING_NAME,
Expand Down Expand Up @@ -139,6 +151,7 @@ def __init__(
self._target_temperature = target_temperature
self._temperature = temperature
self._system_is_metric = hass.config.units is METRIC_SYSTEM
self._goal_specific_status = None
self._status = None
self._lower_bound = lower_bound
self._upper_bound = upper_bound
Expand Down Expand Up @@ -203,41 +216,46 @@ def async_sensor_state_changed(
and self._preset is not None
):
target_temperature = self._preset[PRESET_TARGET_TEMPERATURE]
self._status = GOAL_NOT_REACHED
if is_number(self._temperature) and is_number(target_temperature):
# handle state update settings here
if (
self._state_update_setting[STATE_UPDATE_SETTING_ID] == 0
): # at target temperature
if self._temperature < target_temperature:
self._status = BELOW_TARGET_TEMPERATURE
self._goal_specific_status = BELOW_TARGET_TEMPERATURE
elif self._temperature > target_temperature:
self._status = ABOVE_TARGET_TEMPERATURE
self._goal_specific_status = ABOVE_TARGET_TEMPERATURE
else:
self._status = AT_TARGET_TEMPERATURE
self._goal_specific_status = AT_TARGET_TEMPERATURE
self._status = GOAL_REACHED
elif (
self._state_update_setting[STATE_UPDATE_SETTING_ID] == 1
): # within bounds
if (
self._temperature >= self.get_lower_bound()
and self._temperature <= self.get_upper_bound()
):
self._status = WITHIN_BOUNDS
self._goal_specific_status = WITHIN_BOUNDS
self._status = GOAL_REACHED
else:
self._status = OUTSIDE_BOUNDS
self._goal_specific_status = OUTSIDE_BOUNDS
elif (
self._state_update_setting[STATE_UPDATE_SETTING_ID] == 2
): # below_lower_bound
if self._temperature < self.get_lower_bound():
self._status = BELOW_LOWER_BOUND
self._goal_specific_status = BELOW_LOWER_BOUND
self._status = GOAL_REACHED
else:
self._status = ABOVE_LOWER_BOUND
self._goal_specific_status = ABOVE_LOWER_BOUND
elif (
self._state_update_setting[STATE_UPDATE_SETTING_ID] == 3
): # above_upper_bound
if self._temperature > self.get_upper_bound():
self._status = ABOVE_UPPER_BOUND
self._goal_specific_status = ABOVE_UPPER_BOUND
self._status = GOAL_REACHED
else:
self._status = BELOW_UPPER_BOUND
self._goal_specific_status = BELOW_UPPER_BOUND

# add prediction

Expand Down Expand Up @@ -275,12 +293,6 @@ def async_sensor_state_changed(
self._time_to_target = 0
if self._time_to_target < 0:
self._time_to_target = None
else:
# format to hh:mm:ss
td = str(timedelta(seconds=self._time_to_target))
x = td.split(":")
self._time_to_target = f"{x[0]}:{x[1]}:{x[2].split(".")[0]}"

self.async_schedule_update_ha_state()

def get_lower_bound(self):
Expand Down Expand Up @@ -403,15 +415,16 @@ def extra_state_attributes(self):
else:
sus_attribute = None
return {
"id": self._id,
"source": self._source,
"preset": preset_attribute,
"target temperature": target_temperature_attribute,
"status": self._status,
"lower bound": f"{get_localized_temperature(self._lower_bound,self._system_is_metric)} {localized_temperature_unit}",
"upper bound": f"{get_localized_temperature(self._upper_bound,self._system_is_metric)} {localized_temperature_unit}",
"state update setting": f"{sus_attribute}",
"time to target": self._time_to_target,
SENSOR_ATTR_ID: self._id,
SENSOR_ATTR_SOURCE: self._source,
SENSOR_ATTR_PRESET: preset_attribute,
SENSOR_ATTR_TARGET_TEMPERATURE: target_temperature_attribute,
SENSOR_ATTR_STATUS: self._status,
SENSOR_ATTR_GOAL_SPECIFIC_STATUS: self._goal_specific_status,
SENSOR_ATTR_LOWER_BOUND: f"{get_localized_temperature(self._lower_bound,self._system_is_metric)} {localized_temperature_unit}",
SENSOR_ATTR_UPPER_BOUND: f"{get_localized_temperature(self._upper_bound,self._system_is_metric)} {localized_temperature_unit}",
SENSOR_ATTR_STATE_UPDATE_SETTING: f"{sus_attribute}",
SENSOR_ATTR_TIME_TO_TARGET: self._time_to_target,
}

async def async_added_to_hass(self):
Expand Down
8 changes: 4 additions & 4 deletions custom_components/grill_buddy/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
},
"state_update_settings": {
"at_target_temperature": "At target temperature",
"within_bounds": "Temperature within bounds",
"outside_bounds": "Temperature outside bounds",
"above_upper_bound": "Temperature above upper bound",
"below_lower_bound": "Temperature below lower bound"
"within_bounds": "Temperature within range",
"outside_bounds": "Temperature outside range",
"above_upper_bound": "Temperature above upper threshold",
"below_lower_bound": "Temperature below lower threshold"
}
}

0 comments on commit 712a902

Please sign in to comment.