-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create reset button for wattbox. #22
base: develop
Are you sure you want to change the base?
Conversation
This updates the constants and supports a new button type meant for issuing the reset command inside of pywattbox.
The master outlet is not properly defined in both HTTP and IP, I should have verified that in the IP driver, so this resolves that quirk. Also re-ran the black formatter and noticed that there was a missing unit so I added that. I removed the suggested unit because there is no viable converter for duration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't had a chance to dig into all the different types in HA lately, but is there any way we can combine the entities so there aren't so many? Would think it would be nice to have the outlets with on / off / reset all as one thing. Rather than having on/off in one place and a button elsewhere.
That may be related to #16
@@ -57,9 +57,6 @@ def __init__(self, hass: HomeAssistant, name: str, sensor_type: str) -> None: | |||
self.sensor_type: str = sensor_type | |||
self._attr_name = f"{name} {SENSOR_TYPES[self.sensor_type]['name']}" | |||
self._attr_native_unit_of_measurement = SENSOR_TYPES[self.sensor_type]["unit"] | |||
self._attr_suggested_unit_of_measurement = SENSOR_TYPES[self.sensor_type][ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain what the issue with this was a bit more? It has been a while, but I thought the docs said it was best practice to include it.
name: str = discovery_info[CONF_NAME] | ||
|
||
entities: List[WattBoxEntity] = [] | ||
wattbox: BaseWattBox = hass.data[DOMAIN_DATA][name] | ||
|
||
name_regexp = validate_regex(config, CONF_NAME_REGEXP) | ||
skip_regexp = validate_regex(config, CONF_SKIP_REGEXP) | ||
|
||
for i, outlet in wattbox.outlets.items(): | ||
outlet_name = outlet.name or "" | ||
|
||
# Skip outlets if they match regex | ||
if skip_regexp and skip_regexp.search(outlet_name): | ||
_LOGGER.debug("Skipping outlet #%s - %s", i, outlet_name) | ||
continue | ||
|
||
if name_regexp: | ||
if matched := name_regexp.search(outlet_name): | ||
outlet_name = matched.group() | ||
try: | ||
outlet_name = matched.group(1) | ||
except re.error: | ||
pass | ||
|
||
_LOGGER.debug("Adding outlet reset #%s - %s", i, outlet_name) | ||
entities.append(WattBoxResetButton(hass, name, i, outlet_name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could probably do something shared with this, since switch and button have the same logic except the class they implement. That would ensure the name / skip logic doesn't get out of sync between them.
def validate_regex(config: ConfigType, key: str) -> re.Pattern[str] | None: | ||
regexp_str: str = config.get(key, "") | ||
if regexp_str: | ||
try: | ||
return re.compile(regexp_str) | ||
except re.error: | ||
_LOGGER.error("Invalid %s: %s", key, regexp_str) | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not deduping switch
and button
entirely, should probably put this somewhere shared so they can both import the same function.
This updates the constants and supports a new button type meant for issuing the reset command inside of pywattbox.
I dusted off a wattbox and found that it was easier to control the reset case than it was the on/off case. If you couple this with some of the OutletModeSet commands you can ensure you have a reliable system. This does add a lot more entities as a result, I included a master reset as well. Since you can control the timing with OutletPowerOnDelaySet, I figured there was no point in modifying pywattbox yet.
Only noted errors were
detected blocking call to import_module inside
scrapli and theopen
in ctypes which are both fixable downstream in pywattbox. I fixed the others home assistant issues with this change.