-
Notifications
You must be signed in to change notification settings - Fork 86
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
fix: fix get_resources not adding usps_mail_delivered to configuration selection #966
Conversation
@@ -217,6 +217,12 @@ def process_emails(hass: HomeAssistant, config: ConfigEntry) -> dict: | |||
except Exception as err: | |||
_LOGGER.error("Error updating sensor: %s reason: %s", sensor, err) | |||
|
|||
# Update usps_mail_delivered | |||
try: | |||
fetch(hass, config, account, data, "usps_mail_delivered") |
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.
The sensor would already be in the resources
and searched for twice.
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 added some additional logging in my testing and I don't think it's in resources
. If resources
is set by get_resources()
, SENSOR_TYPES
does not contain the BinarySensors. I think.
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.
resources
is set here:
resources = config.get(CONF_RESOURCES) |
The list comes from the configuration.
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.
Please correct me in I am wrong. This is my first time digging into HA. Does config.get(CONF_RESOURCES)
get set by:
Home-Assistant-Mail-And-Packages/custom_components/mail_and_packages/config_flow.py
Lines 211 to 213 in 4a39728
vol.Required( | |
CONF_RESOURCES, default=_get_default(CONF_RESOURCES) | |
): cv.multi_select(get_resources()), |
If so
get_resources()
here:Home-Assistant-Mail-And-Packages/custom_components/mail_and_packages/helpers.py
Lines 94 to 103 in 4a39728
def get_resources() -> dict: | |
"""Resource selection schema. | |
Returns dict of user selected sensors | |
""" | |
known_available_resources = { | |
sensor_id: sensor.name for sensor_id, sensor in SENSOR_TYPES.items() | |
} | |
return known_available_resources |
uses
SENSOR_TYPES
defined here:SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = { |
which does not include
usps_mail_delivered
defined here:Home-Assistant-Mail-And-Packages/custom_components/mail_and_packages/const.py
Lines 1157 to 1161 in 4a39728
"usps_mail_delivered": BinarySensorEntityDescription( | |
name="USPS Mail Delivered", | |
key="usps_mail_delivered", | |
entity_registry_enabled_default=False, | |
), |
I must be missing something. :)
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.
Ah you are correct, it's been excluded from the resources in error. That's where the bug needs to be fixed.
get_resources() needs the fixing.
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.
Feel free to give it a run on a test HA instance if you like too, all the sensors will now be sorted alphabetically.
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.
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 you refresh does it show "on"?
if so, this will be an bug in HA not updating the front end.
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.
Interesting. Yep. Issue with HA front end. I had clicked around to different views in HA and even restarted the Mail and Packages integration, but it wasn't until I refreshed the browser that it updated.
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've noticed this issue after the 2024.8.2 update.
fix: fix get_resources not adding usps_mail_delivered to configuration selection
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.
This should fix the import linting errors.
BinarySensorDeviceClass, | ||
BinarySensorEntityDescription, | ||
) | ||
from .entity import MailandPackagesBinarySensorEntityDescription |
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.
from .entity import MailandPackagesBinarySensorEntityDescription | |
from homeassistant.components.binary_sensor import BinarySensorDeviceClass |
BinarySensorEntityDescription, | ||
) | ||
from .entity import MailandPackagesBinarySensorEntityDescription | ||
from homeassistant.components.binary_sensor import BinarySensorDeviceClass |
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.
from homeassistant.components.binary_sensor import BinarySensorDeviceClass | |
from homeassistant.components.sensor import SensorDeviceClass, SensorEntityDescription |
BinarySensorEntityDescription, | ||
) | ||
from .entity import MailandPackagesBinarySensorEntityDescription | ||
from homeassistant.components.binary_sensor import BinarySensorDeviceClass | ||
from homeassistant.components.sensor import SensorDeviceClass, SensorEntityDescription |
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.
from homeassistant.components.sensor import SensorDeviceClass, SensorEntityDescription | |
from homeassistant.helpers.entity import EntityCategory |
BinarySensorEntityDescription, | ||
) | ||
from .entity import MailandPackagesBinarySensorEntityDescription | ||
from homeassistant.components.binary_sensor import BinarySensorDeviceClass | ||
from homeassistant.components.sensor import SensorDeviceClass, SensorEntityDescription | ||
from homeassistant.helpers.entity import EntityCategory |
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.
from homeassistant.helpers.entity import EntityCategory |
BinarySensorEntityDescription, | ||
) | ||
from .entity import MailandPackagesBinarySensorEntityDescription | ||
from homeassistant.components.binary_sensor import BinarySensorDeviceClass | ||
from homeassistant.components.sensor import SensorDeviceClass, SensorEntityDescription | ||
from homeassistant.helpers.entity import EntityCategory | ||
|
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.
from .entity import MailandPackagesBinarySensorEntityDescription |
Proposed change
Fix bug in delivered USPS mail implementation.
Type of change
Additional information
fetch() is never called with sensor="usps_mail_delivered" in process_emails() as resources does not contain the BinarySensors.
This is probably just a temporary fix.