Skip to content

Commit

Permalink
v0.0.19 - fixing bug introduced in v0.0.18 and adding naming options …
Browse files Browse the repository at this point in the history
…to component to enable fixing of #21
  • Loading branch information
jeroenterheerdt committed May 28, 2020
1 parent 58747f9 commit 60778b5
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
13 changes: 10 additions & 3 deletions custom_components/smart_irrigation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
CONF_SHOW_UNITS,
CONF_AUTO_REFRESH,
CONF_AUTO_REFRESH_TIME,
CONF_NAME,
)

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -108,6 +109,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
longitude = hass.config.as_dict().get(CONF_LONGITUDE)
elevation = hass.config.as_dict().get(CONF_ELEVATION)

name = entry.title

# handle options: lead time, max duration, force_mode_duration, show units, auto refresh, auto refresh time
lead_time = entry.options.get(CONF_LEAD_TIME, 0)
maximum_duration = entry.options.get(CONF_MAXIMUM_DURATION, -1)
Expand Down Expand Up @@ -138,6 +141,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
show_units=show_units,
auto_refresh=auto_refresh,
auto_refresh_time=auto_refresh_time,
name=name,
)

await coordinator.async_refresh()
Expand All @@ -155,16 +159,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):

# register the services
hass.services.async_register(
DOMAIN, SERVICE_RESET_BUCKET, coordinator.handle_reset_bucket
DOMAIN, f"{name}_{SERVICE_RESET_BUCKET}", coordinator.handle_reset_bucket,
)
hass.services.async_register(
DOMAIN,
SERVICE_CALCULATE_HOURLY_ADJUSTED_RUN_TIME,
f"{name}_{SERVICE_CALCULATE_HOURLY_ADJUSTED_RUN_TIME}",
coordinator.handle_calculate_hourly_adjusted_run_time,
)
hass.services.async_register(
DOMAIN,
SERVICE_CALCULATE_DAILY_ADJUSTED_RUN_TIME,
f"{name}_{SERVICE_CALCULATE_DAILY_ADJUSTED_RUN_TIME}",
coordinator.handle_calculate_daily_adjusted_run_time,
)

Expand Down Expand Up @@ -224,6 +228,7 @@ def __init__(
show_units,
auto_refresh,
auto_refresh_time,
name,
):
"""Initialize."""
self.api = OWMClient(api_key=api_key, longitude=longitude, latitude=latitude)
Expand All @@ -245,11 +250,13 @@ def __init__(
self.show_units = show_units
self.auto_refresh = auto_refresh
self.auto_refresh_time = auto_refresh_time
self.name = name
self.platforms = []
self.bucket = 0
self.hass = hass
self.entities = {}
self.entry_setup_completed = False
# should this be name? or domain?
super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=SCAN_INTERVAL)

# last update of the day happens at specified local time if auto_refresh is on
Expand Down
8 changes: 7 additions & 1 deletion custom_components/smart_irrigation/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
CONF_SHOW_UNITS,
CONF_AUTO_REFRESH,
CONF_AUTO_REFRESH_TIME,
CONF_NAME,
)


Expand All @@ -52,6 +53,7 @@ class SmartIrrigationConfigFlowHandler(config_entries.ConfigFlow, domain=DOMAIN)
def __init__(self):
"""Initialize."""
self._api_key = None
self._name = NAME
self._reference_et = {}
self._errors = {}

Expand All @@ -66,7 +68,8 @@ async def async_step_step3(self, user_input=None):
if user_input is not None:
user_input[CONF_API_KEY] = self._api_key
user_input[CONF_REFERENCE_ET] = self._reference_et
return self.async_create_entry(title=NAME, data=user_input)
user_input[CONF_NAME] = self._name
return self.async_create_entry(title=self._name, data=user_input)
return await self._show_config_form(user_input)

async def async_step_step2(self, user_input=None):
Expand Down Expand Up @@ -125,6 +128,7 @@ async def async_step_user(self, user_input=None):
if valid_api:
# store values entered
self._api_key = user_input[CONF_API_KEY].strip()
self._name = user_input[CONF_NAME]
# show next step
return await self._show_step2(user_input)
else:
Expand Down Expand Up @@ -187,6 +191,7 @@ async def _show_config_form(self, user_input):
step_id="user",
data_schema=vol.Schema(
{
vol.Required(CONF_NAME, default=NAME): str,
vol.Required(CONF_API_KEY): str,
# vol.Required(CONF_REFERENCE_ET_1): vol.Coerce(float),
# vol.Required(CONF_REFERENCE_ET_2): vol.Coerce(float),
Expand Down Expand Up @@ -249,6 +254,7 @@ class SmartIrrigationOptionsFlowHandler(config_entries.OptionsFlow):
def __init__(self, config_entry):
"""Initialize HACS options flow."""
self.config_entry = config_entry
_LOGGER.warning("config_entry: {}".format(config_entry))
self.options = dict(config_entry.options)
self._errors = {}

Expand Down
3 changes: 2 additions & 1 deletion custom_components/smart_irrigation/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
DOMAIN = "smart_irrigation"
NAME = "Smart Irrigation"
DOMAIN_DATA = f"{DOMAIN}_data"
VERSION = "0.0.18"
VERSION = "0.0.19"

ISSUE_URL = "https://github.com/jeroenterheerdt/HASmartIrrigation/issues"

Expand Down Expand Up @@ -51,6 +51,7 @@
CONF_SHOW_UNITS = "show_units"
CONF_AUTO_REFRESH = "auto_refresh"
CONF_AUTO_REFRESH_TIME = "auto_refresh_time"
CONF_NAME = "name"

# Events
EVENT_BUCKET_UPDATED = "smart_irrigation_bucket_updated_event"
Expand Down
6 changes: 4 additions & 2 deletions custom_components/smart_irrigation/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ async def async_added_to_hass(self):
try:
a_val = state.attributes[a]
# no split needed if we don't show units
if self.coordinator.show_units or " " in a_val:
if self.coordinator.show_units or (
isinstance(a_val, str) and " " in a_val
):
numeric_part = a_val.split(" ")[0]
else:
numeric_part = float(a_val)
Expand Down Expand Up @@ -189,7 +191,7 @@ def _bucket_updated(self, ev: Event):
@property
def name(self):
"""Return the name of the sensor."""
return f"{DEFAULT_NAME} {self.type}"
return f"{self.coordinator.name} {self.type}"

def update_state(self):
"""Update the state."""
Expand Down
3 changes: 2 additions & 1 deletion custom_components/smart_irrigation/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"title": "Smart Irrigation - Step 1/3: Open Weather Map API",
"description": "If you need help with the configuration, please see https://github.com/jeroenterheerdt/HASmartIrrigation",
"data": {
"api_key": "API key for Open Weather Map"
"api_key": "API key for Open Weather Map",
"name": "Unique name of the instance"
}
},
"step2": {
Expand Down
3 changes: 2 additions & 1 deletion custom_components/smart_irrigation/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"title": "Smart Irrigation - Step 1/3: Open Weather Map API",
"description": "If you need help with the configuration, please see https://github.com/jeroenterheerdt/HASmartIrrigation",
"data": {
"api_key": "API key for Open Weather Map"
"api_key": "API key for Open Weather Map",
"name": "Unique name of the instance"
}
},
"step2": {
Expand Down

0 comments on commit 60778b5

Please sign in to comment.