Skip to content

Commit

Permalink
feat: Add ability to disable calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerSelwyn committed May 27, 2024
1 parent f700198 commit 72d6617
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 6 deletions.
4 changes: 4 additions & 0 deletions custom_components/o365/classes/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
CONF_BASIC_CALENDAR,
CONF_CHAT_SENSORS,
CONF_EMAIL_SENSORS,
CONF_ENABLE_CALENDAR,
CONF_ENABLE_UPDATE,
CONF_GROUPS,
CONF_QUERY_SENSORS,
Expand Down Expand Up @@ -172,6 +173,9 @@ def _get_permissions(self):
return permissions

def _build_calendar_permissions(self):
if not self._config.get(CONF_ENABLE_CALENDAR, True):
return

if self._config.get(CONF_BASIC_CALENDAR, False):
if self._enable_update:
_LOGGER.warning(
Expand Down
1 change: 1 addition & 0 deletions custom_components/o365/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class EventResponse(Enum):
CONF_DUE_HOURS_FORWARD_TO_GET = "due_end_offset"
CONF_EMAIL_ACCOUNT = "email_account"
CONF_EMAIL_SENSORS = "email_sensor"
CONF_ENABLE_CALENDAR = "enable_calendar"
CONF_ENABLE_UPDATE = "enable_update"
CONF_ENTITIES = "entities"
CONF_ENTITY_KEY = "entity_key"
Expand Down
14 changes: 9 additions & 5 deletions custom_components/o365/helpers/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
CONF_COORDINATOR_EMAIL,
CONF_COORDINATOR_SENSORS,
CONF_EMAIL_SENSORS,
CONF_ENABLE_CALENDAR,
CONF_ENABLE_UPDATE,
CONF_KEYS_EMAIL,
CONF_KEYS_SENSORS,
Expand All @@ -39,7 +40,8 @@ async def do_setup(hass, config, account, account_name, conf_type, perms):
chat_sensors = config.get(CONF_CHAT_SENSORS, [])
todo_sensors = config.get(CONF_TODO_SENSORS, [])
auto_reply_sensors = config.get(CONF_AUTO_REPLY_SENSORS, [])
enable_update = config.get(CONF_ENABLE_UPDATE, True)
enable_update = config.get(CONF_ENABLE_UPDATE, False)
enable_calendar = config.get(CONF_ENABLE_CALENDAR, True)

account_config = {
CONF_CLIENT_ID: config.get(CONF_CLIENT_ID),
Expand All @@ -51,6 +53,7 @@ async def do_setup(hass, config, account, account_name, conf_type, perms):
CONF_TODO_SENSORS: todo_sensors,
CONF_AUTO_REPLY_SENSORS: auto_reply_sensors,
CONF_ENABLE_UPDATE: enable_update,
CONF_ENABLE_CALENDAR: enable_calendar,
CONF_TRACK_NEW_CALENDAR: config.get(CONF_TRACK_NEW_CALENDAR, True),
CONF_ACCOUNT_NAME: config.get(CONF_ACCOUNT_NAME, ""),
CONF_CONFIG_TYPE: conf_type,
Expand Down Expand Up @@ -97,11 +100,12 @@ async def _async_email_setup(hass, account_config):


def _load_platforms(hass, account_name, config, account_config):
hass.async_create_task(
discovery.async_load_platform(
hass, "calendar", DOMAIN, {CONF_ACCOUNT_NAME: account_name}, config
if account_config[CONF_ENABLE_CALENDAR]:
hass.async_create_task(
discovery.async_load_platform(
hass, "calendar", DOMAIN, {CONF_ACCOUNT_NAME: account_name}, config
)
)
)
if account_config[CONF_ENABLE_UPDATE]:
hass.async_create_task(
discovery.async_load_platform(
Expand Down
2 changes: 2 additions & 0 deletions custom_components/o365/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
CONF_DUE_HOURS_BACKWARD_TO_GET,
CONF_DUE_HOURS_FORWARD_TO_GET,
CONF_EMAIL_SENSORS,
CONF_ENABLE_CALENDAR,
CONF_ENABLE_UPDATE,
CONF_ENTITIES,
CONF_EXCLUDE,
Expand Down Expand Up @@ -210,6 +211,7 @@ def validate(obj: dict[str, Any]) -> dict[str, Any]:
vol.Required(CONF_CLIENT_ID): cv.string,
vol.Required(CONF_CLIENT_SECRET): cv.string,
vol.Optional(CONF_TRACK_NEW_CALENDAR, default=True): bool,
vol.Optional(CONF_ENABLE_CALENDAR, default=True): bool,
vol.Optional(CONF_ENABLE_UPDATE, default=False): bool,
vol.Optional(CONF_GROUPS, default=False): bool,
vol.Required(CONF_ACCOUNT_NAME, ""): cv.string,
Expand Down
1 change: 1 addition & 0 deletions docs/installation_and_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Key | Type | Required | Description
`client_id` | `string` | `True` | Client ID from your O365 application.
`client_secret` | `string` | `True` | Client Secret from your O365 application.
`alt_auth_method` | `boolean` | `False` | If False (default), authentication is not dependent on internet access to your HA instance. [See Authentication](./authentication.md)
`enable_calendar` | `boolean` | `False` | If True (**default is True**), this will enable calendars within the integration
`enable_update` | `boolean` | `False` | If True (**default is False**), this will enable the various services that allow the sending of emails and updates to calendars
`basic_calendar` | `boolean` | `False` | If True (**default is False**), the permission requested will be `calendar.ReadBasic`. `enable_update: true` = true cannot be used if `basic_calendar: true`
`groups` | `boolean` | `False` | If True (**default is False**), will enable support for group calendars. No discovery is performed. You will need to know how to get the group ID from the MS Graph API. *Not for use on shared mailboxes*
Expand Down
2 changes: 1 addition & 1 deletion docs/permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ nav_order: 3
# Permissions

Under "API Permissions" click Add a permission, then Microsoft Graph, then Delegated permission, and add the permissions as detailed in the list and table below:
* Calendar - The core permissions required for calendars to work *Note the requirement for `.Shared` permissions for shared mailboxes*
* Calendar - For calendars *Note the requirement for `.Shared` permissions for shared mailbox calendars*
* Email - For an email_sensor or a query_sensor *Note the requirement for `.Shared` permissions for shared mailboxes*
* Status - For a status_sensor
* Chat - For a chat_sensor
Expand Down

0 comments on commit 72d6617

Please sign in to comment.