mirror of
https://github.com/home-assistant/core
synced 2024-09-06 10:29:55 +02:00
Add charset to imap component. (#28258)
This commit is contained in:
parent
a9db2ead33
commit
6ac7796fb7
@ -23,6 +23,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
CONF_SERVER = "server"
|
CONF_SERVER = "server"
|
||||||
CONF_FOLDER = "folder"
|
CONF_FOLDER = "folder"
|
||||||
CONF_SEARCH = "search"
|
CONF_SEARCH = "search"
|
||||||
|
CONF_CHARSET = "charset"
|
||||||
|
|
||||||
DEFAULT_PORT = 993
|
DEFAULT_PORT = 993
|
||||||
|
|
||||||
@ -35,6 +36,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
vol.Required(CONF_PASSWORD): cv.string,
|
vol.Required(CONF_PASSWORD): cv.string,
|
||||||
vol.Required(CONF_SERVER): cv.string,
|
vol.Required(CONF_SERVER): cv.string,
|
||||||
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
||||||
|
vol.Optional(CONF_CHARSET, default="utf-8"): cv.string,
|
||||||
vol.Optional(CONF_FOLDER, default="INBOX"): cv.string,
|
vol.Optional(CONF_FOLDER, default="INBOX"): cv.string,
|
||||||
vol.Optional(CONF_SEARCH, default="UnSeen UnDeleted"): cv.string,
|
vol.Optional(CONF_SEARCH, default="UnSeen UnDeleted"): cv.string,
|
||||||
}
|
}
|
||||||
@ -49,6 +51,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||||||
config.get(CONF_PASSWORD),
|
config.get(CONF_PASSWORD),
|
||||||
config.get(CONF_SERVER),
|
config.get(CONF_SERVER),
|
||||||
config.get(CONF_PORT),
|
config.get(CONF_PORT),
|
||||||
|
config.get(CONF_CHARSET),
|
||||||
config.get(CONF_FOLDER),
|
config.get(CONF_FOLDER),
|
||||||
config.get(CONF_SEARCH),
|
config.get(CONF_SEARCH),
|
||||||
)
|
)
|
||||||
@ -62,13 +65,14 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||||||
class ImapSensor(Entity):
|
class ImapSensor(Entity):
|
||||||
"""Representation of an IMAP sensor."""
|
"""Representation of an IMAP sensor."""
|
||||||
|
|
||||||
def __init__(self, name, user, password, server, port, folder, search):
|
def __init__(self, name, user, password, server, port, charset, folder, search):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self._name = name or user
|
self._name = name or user
|
||||||
self._user = user
|
self._user = user
|
||||||
self._password = password
|
self._password = password
|
||||||
self._server = server
|
self._server = server
|
||||||
self._port = port
|
self._port = port
|
||||||
|
self._charset = charset
|
||||||
self._folder = folder
|
self._folder = folder
|
||||||
self._email_count = None
|
self._email_count = None
|
||||||
self._search = search
|
self._search = search
|
||||||
@ -150,7 +154,9 @@ class ImapSensor(Entity):
|
|||||||
"""Check the number of found emails."""
|
"""Check the number of found emails."""
|
||||||
if self._connection:
|
if self._connection:
|
||||||
await self._connection.noop()
|
await self._connection.noop()
|
||||||
result, lines = await self._connection.search(self._search)
|
result, lines = await self._connection.search(
|
||||||
|
self._search, charset=self._charset
|
||||||
|
)
|
||||||
|
|
||||||
if result == "OK":
|
if result == "OK":
|
||||||
self._email_count = len(lines[0].split())
|
self._email_count = len(lines[0].split())
|
||||||
|
Loading…
Reference in New Issue
Block a user