Skip to content
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

Update __init__.py #723

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions custom_components/shelly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
__version__ as HAVERSION )
from homeassistant import config_entries
from homeassistant.helpers import discovery
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.restore_state import RestoreStateData
from homeassistant.helpers.storage import Store
Expand Down Expand Up @@ -192,8 +193,7 @@ async def update_listener(self, hass, config_entry):

await self.update_config()

entity_reg = \
await self.hass.helpers.entity_registry.async_get_registry()
entity_reg = er.async_get(self.hass)
for entity in self.entities:
if hasattr(entity, 'config_updated'):
entity.config_updated()
Expand Down Expand Up @@ -260,10 +260,8 @@ async def update_config(self):
self.add_device("sensor", attr)
if not conf.get(CONF_VERSION) and self.version_added:
self.version_added = False
entity_reg = \
await self.hass.helpers.entity_registry.async_get_registry()
entity_id = "sensor." + slugify(conf.get(CONF_OBJECT_ID_PREFIX)) + "_version"
entity_reg.async_remove(entity_id)
er.async_get(self.hass).async_remove(entity_id).async_remove(entity_id)

def update_config_attributes(self):
self.conf_attributes = set(self.conf.get(CONF_ATTRIBUTES))
Expand Down Expand Up @@ -352,8 +350,7 @@ async def start_up(self):
'extra' : {'ip-addr': pys.host_ip}}
self.add_device("sensor", attr)

entity_reg = \
await self.hass.helpers.entity_registry.async_get_registry()
entity_reg = er.async_get(self.hass)
entities_to_remove = []
entities_to_fix_attr = []
restore_expired = dt_util.as_utc(datetime.now()) - timedelta(hours=12)
Expand Down Expand Up @@ -419,8 +416,7 @@ async def start_up(self):
async def stop(self, _=None):
"""Stop Shelly."""
_LOGGER.info("Shutting down Shelly")
entity_reg = \
await self.hass.helpers.entity_registry.async_get_registry()
entity_reg = er.async_get(self.hass)
# entities_to_remove = []
# for entity in entity_reg.entities.values():
# if entity.platform == "shelly":
Expand Down